diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 66264662c4d0075d416c24eabbfdf868700ae0b6..eddc484d3cef3bd114bc35538b844ff03b537d69 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -283,6 +283,7 @@ group("unittest") { "auto_startup_callback_stub_test:unittest", "auto_startup_info_test:unittest", "background_task_observer_test:unittest", + "block_all_app_start_interceptor_test:unittest", "bundle_mgr_helper_second_test:unittest", "bundle_mgr_helper_test:unittest", "cache_process_manager_second_test:unittest", diff --git a/test/unittest/ability_runtime_start_options_test/ability_runtime_start_options_test.cpp b/test/unittest/ability_runtime_start_options_test/ability_runtime_start_options_test.cpp index c6a93bef2efacbb53a0d1f4976a2793750c86032..464fe4ea6078e8804f64cdc42260b69f0ae0841c 100644 --- a/test/unittest/ability_runtime_start_options_test/ability_runtime_start_options_test.cpp +++ b/test/unittest/ability_runtime_start_options_test/ability_runtime_start_options_test.cpp @@ -895,7 +895,7 @@ HWTEST_F(AbilityRuntimeStartOptionsTest, OH_AbilityRuntime_SetStartOptionsStartV { AbilityRuntime_StartOptions* startOptions = nullptr; AbilityRuntime_StartVisibility startVisibility = AbilityRuntime_StartVisibility::ABILITY_RUNTIME_HIDE_UPON_START; - EXPECT_EQ(OH_AbilityRuntime_SetStartOptionsWindowWidth(startOptions, startVisibility), + EXPECT_EQ(OH_AbilityRuntime_SetStartOptionsStartVisibility(startOptions, startVisibility), ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); } diff --git a/test/unittest/block_all_app_start_interceptor_test/BUILD.gn b/test/unittest/block_all_app_start_interceptor_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9f2fde955a841655b6b0f81e9664ae4ca760a0b3 --- /dev/null +++ b/test/unittest/block_all_app_start_interceptor_test/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2025 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/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("block_all_app_start_interceptor_test") { + module_out_path = module_output_path + cflags_cc = [] + include_dirs = [ + "${ability_runtime_path}/services/abilitymgr/include/interceptor", + "${ability_runtime_path}/services/common/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/interceptor/block_all_app_start_interceptor.cpp", + "block_all_app_start_interceptor_test.cpp", + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + deps = [ ":block_all_app_start_interceptor_test" ] +} diff --git a/test/unittest/block_all_app_start_interceptor_test/block_all_app_start_interceptor_test.cpp b/test/unittest/block_all_app_start_interceptor_test/block_all_app_start_interceptor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4241e4ab6f75ebf5843da695a34974685ed65b5 --- /dev/null +++ b/test/unittest/block_all_app_start_interceptor_test/block_all_app_start_interceptor_test.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#define private public +#define protected public +#include "interceptor/block_all_app_start_interceptor.h" +#undef private +#undef protected + +#include "hilog_tag_wrapper.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AAFwk { +class BlockAllAppStartInterceptorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +public: +}; + +void BlockAllAppStartInterceptorTest::SetUpTestCase() +{} + +void BlockAllAppStartInterceptorTest::TearDownTestCase() +{} + +void BlockAllAppStartInterceptorTest::SetUp() +{} + +void BlockAllAppStartInterceptorTest::TearDown() +{} + +/** + * @tc.name: BlockAllAppStartInterceptorTest_DoProcess_001 + * @tc.desc: DoProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(BlockAllAppStartInterceptorTest, DoProcess_001, TestSize.Level1) +{ + BlockAllAppStartInterceptor blockAllAppStartInterceptor; + Want want; + int requestCode = 123; + int32_t userId = 1001; + bool isWithUI = true; + sptr callerToken = nullptr; + std::function shouldBlockAllAppStartFunc = nullptr; + AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc); + auto ret = blockAllAppStartInterceptor.DoProcess(param); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/** + * @tc.name: BlockAllAppStartInterceptorTest_DoProcess_002 + * @tc.desc: DoProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(BlockAllAppStartInterceptorTest, DoProcess_002, TestSize.Level1) +{ + BlockAllAppStartInterceptor blockAllAppStartInterceptor; + Want want; + int requestCode = 123; + int32_t userId = 1001; + bool isWithUI = true; + sptr callerToken = nullptr; + std::function shouldBlockAllAppStartFunc = []() -> bool { + return true; + }; + AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc); + auto ret = blockAllAppStartInterceptor.DoProcess(param); + EXPECT_EQ(ret, ERR_ALL_APP_START_BLOCKED); +} + +/** + * @tc.name: BlockAllAppStartInterceptorTest_DoProcess_003 + * @tc.desc: DoProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(BlockAllAppStartInterceptorTest, DoProcess_003, TestSize.Level1) +{ + BlockAllAppStartInterceptor blockAllAppStartInterceptor; + Want want; + int requestCode = 123; + int32_t userId = 1001; + bool isWithUI = true; + sptr callerToken = nullptr; + std::function shouldBlockAllAppStartFunc = []() -> bool { + return false; + }; + AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc); + auto ret = blockAllAppStartInterceptor.DoProcess(param); + EXPECT_EQ(ret, ERR_OK); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/start_options_impl_test/start_options_impl_test.cpp b/test/unittest/start_options_impl_test/start_options_impl_test.cpp index af84108c95908b23dea949a7f6863e0ec00dc1e3..af90701acc94f6907b86c2ae9200206a5ca13e84 100644 --- a/test/unittest/start_options_impl_test/start_options_impl_test.cpp +++ b/test/unittest/start_options_impl_test/start_options_impl_test.cpp @@ -600,6 +600,56 @@ HWTEST_F(StartOptionsImplTest, SetStartOptionsStartVisibility_001, testing::ext: TAG_LOGI(AAFwkTag::TEST, "SetStartOptionsStartVisibility_001 end"); } +// Test cases +// Test SetStartOptionsStartVisibility function - Failure case +/** + * @tc.name: SetStartOptionsStartVisibility_002 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, SetStartOptionsStartVisibility_002, testing::ext::TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "SetStartOptionsStartVisibility_002 begin"); + // Arrange + AbilityRuntime_ErrorCode expectedErrorCode = ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; + + // Act + AbilityRuntime_StartVisibility startVisibility = AbilityRuntime_StartVisibility(100); + AbilityRuntime_ErrorCode resultErrorCode = startOptions->SetStartOptionsStartVisibility(startVisibility); + TAG_LOGI(AAFwkTag::TEST, + "SetStartOptionsStartVisibility_002 resultErrorCode=%{public}d,expectedErrorCode=%{public}d", + resultErrorCode, expectedErrorCode); + + // Assert + EXPECT_EQ(expectedErrorCode, resultErrorCode); + TAG_LOGI(AAFwkTag::TEST, "SetStartOptionsStartVisibility_002 end"); +} + +// Test cases +// Test SetStartOptionsStartVisibility function - Failure case +/** + * @tc.name: SetStartOptionsStartVisibility_003 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, SetStartOptionsStartVisibility_003, testing::ext::TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "SetStartOptionsStartVisibility_003 begin"); + // Arrange + AbilityRuntime_ErrorCode expectedErrorCode = ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; + + // Act + AbilityRuntime_StartVisibility startVisibility = AbilityRuntime_StartVisibility(-1); + AbilityRuntime_ErrorCode resultErrorCode = startOptions->SetStartOptionsStartVisibility(startVisibility); + TAG_LOGI(AAFwkTag::TEST, + "SetStartOptionsStartVisibility_003 resultErrorCode=%{public}d,expectedErrorCode=%{public}d", + resultErrorCode, expectedErrorCode); + + // Assert + EXPECT_EQ(expectedErrorCode, resultErrorCode); + TAG_LOGI(AAFwkTag::TEST, "SetStartOptionsStartVisibility_003 end"); +} + // Test cases // Test GetStartOptionsStartVisibility function - Normal case /** @@ -724,6 +774,25 @@ HWTEST_F(StartOptionsImplTest, SetStartOptionsStartWindowIcon_004, testing::ext: #endif } +// Test cases +// Test SetStartOptionsStartWindowIcon function - Normal case +/** + * @tc.name: SetStartOptionsStartWindowIcon_005 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, SetStartOptionsStartWindowIcon_005, testing::ext::TestSize.Level1) +{ +#ifdef START_WINDOW_OPTIONS_WITH_PIXELMAP + OH_PixelmapNative *startWindowIcon = new OH_PixelmapNative(nullptr); + startOptions->options.startWindowOption = nullptr; + EXPECT_EQ(startOptions->SetStartOptionsStartWindowIcon(startWindowIcon), + ABILITY_RUNTIME_ERROR_CODE_NO_ERROR); + EXPECT_NE(startOptions->options.startWindowOption, nullptr); + delete startWindowIcon; +#endif +} + // Test cases // Test GetStartOptionsStartWindowIcon function - Normal case /** @@ -821,6 +890,57 @@ HWTEST_F(StartOptionsImplTest, GetStartOptionsStartWindowIcon_004, testing::ext: #endif } +// Test cases +// Test SetStartOptionsStartWindowIcon function - Normal case +/** + * @tc.name: GetStartOptionsStartWindowIcon_005 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, GetStartOptionsStartWindowIcon_005, testing::ext::TestSize.Level1) +{ +#ifdef START_WINDOW_OPTIONS_WITH_PIXELMAP + // Arrange + startOptions->options.startWindowOption = std::make_shared(); + startOptions->options.startWindowOption->hasStartWindow = true; + startOptions->options.startWindowOption->startWindowIcon = std::make_shared(); + OH_PixelmapNative* startWindowIcon = new OH_PixelmapNative(nullptr); + + // Act + AbilityRuntime_ErrorCode result = startOptions->GetStartOptionsStartWindowIcon(&startWindowIcon); + + // Assert + EXPECT_EQ(ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID, result); + delete startWindowIcon; +#endif +} + +// Test cases +// Test SetStartOptionsStartWindowIcon function - Normal case +/** + * @tc.name: GetStartOptionsStartWindowIcon_006 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, GetStartOptionsStartWindowIcon_006, testing::ext::TestSize.Level1) +{ +#ifdef START_WINDOW_OPTIONS_WITH_PIXELMAP + // Arrange + startOptions->options.startWindowOption = std::make_shared(); + startOptions->options.startWindowOption->hasStartWindow = true; + startOptions->options.startWindowOption->startWindowIcon = std::make_shared(); + OH_PixelmapNative* startWindowIcon = nullptr; + + // Act + AbilityRuntime_ErrorCode result = startOptions->GetStartOptionsStartWindowIcon(&startWindowIcon); + + // Assert + EXPECT_EQ(ABILITY_RUNTIME_ERROR_CODE_NO_ERROR, result); + EXPECT_NE(nullptr, startWindowIcon); + delete startWindowIcon; +#endif +} + // Test cases // Test SetStartOptionsStartWindowBackgroundColor function /** @@ -1118,6 +1238,20 @@ HWTEST_F(StartOptionsImplTest, GetStartOptionsSupportedWindowModes_004, testing: free(supportedWindowModes); } +// Test cases +// Test GetStartOptionsSupportedWindowModes function +/** + * @tc.name: GetStartOptionsSupportedWindowModes_005 + * @tc.desc: test class StartOptions number function + * @tc.type: FUNC + */ +HWTEST_F(StartOptionsImplTest, GetStartOptionsSupportedWindowModes_005, testing::ext::TestSize.Level1) +{ + size_t size = 0; + EXPECT_EQ(ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID, + startOptions->GetStartOptionsSupportedWindowModes(nullptr, size)); +} + // Test cases // Test SetStartOptionsMinWindowWidth function - Normal case /**