From a0225d7855423411431385e6f3cc255439a63a22 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jun 2025 21:16:10 +0800 Subject: [PATCH] add window_visiblity Signed-off-by: unknown --- test/new_test/unit_test/BUILD.gn | 4 +- .../BUILD.gn | 107 +++++++++++++++ ...indow_visibility_changed_listener_test.cpp | 126 ++++++++++++++++++ ...indow_visibility_changed_listener_test.cpp | 1 - 4 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/BUILD.gn create mode 100644 test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp diff --git a/test/new_test/unit_test/BUILD.gn b/test/new_test/unit_test/BUILD.gn index af86670a5d1..17e5a80fcd7 100644 --- a/test/new_test/unit_test/BUILD.gn +++ b/test/new_test/unit_test/BUILD.gn @@ -16,5 +16,7 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") group("unittest") { testonly = true - deps = [ "ability_auto_startup_client_unit_test:unittest" ] + deps = [ "ability_auto_startup_client_unit_test:unittest", + "window_visibility_changed_listener_test:unittest", + ] } diff --git a/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/BUILD.gn b/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/BUILD.gn new file mode 100644 index 00000000000..7e41dea51d3 --- /dev/null +++ b/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/BUILD.gn @@ -0,0 +1,107 @@ +# 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("window_visibility_changed_listener_test") { + module_out_path = module_output_path + include_dirs = [ + "${ability_runtime_services_path}/appdfr/include", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${ability_runtime_test_path}/mock/common/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "mock/include", + ] + + sources = [ "${ability_runtime_services_path}/abilitymgr/src/window_visibility_changed_listener.cpp" ] + sources += [ + "window_visibility_changed_listener_test.cpp", # add mock file + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", + "${ability_runtime_innerkits_path}/ability_manager:mission_info", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/abilitymgr:mission_list", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:task_handler_wrap", + "${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", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:extractortool", + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "napi:ace_napi", + "resource_management:global_resmgr", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] + + defines = [ "SUPPORT_UPMS" ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "image_framework:image_native" ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +group("unittest") { + testonly = true + + deps = [ + ":window_visibility_changed_listener_test", + ] +} diff --git a/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp b/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp new file mode 100644 index 00000000000..6823487aefa --- /dev/null +++ b/test/new_test/unit_test/abilitymgr/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2024 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 +#include + +#define private public +#include "window_visibility_changed_listener.h" +#undef private +#include "hilog_tag_wrapper.h" +#include "window_visibility_info.h" + +using namespace testing; +using namespace testing::ext; +using namespace testing::mt; + +namespace OHOS { +namespace AAFwk { +namespace { +constexpr int32_t DEBUGINFOS_SIZE = 0; +constexpr int32_t ABILITYTOKENS_SIZE = 0; +constexpr int32_t RECORD_ID = 1; +constexpr uint32_t WINDOW_ID = 100; +constexpr pid_t PID = 10; +constexpr int32_t RECORD_MAP_SIZE = 1; +constexpr int32_t DEBUG_INFOS_SIZE = 1; +constexpr int32_t ABILITY_TOKENS_SIZE = 1; +} +class WindowVisibilityChangedListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void WindowVisibilityChangedListenerTest::SetUpTestCase(void) +{} + +void WindowVisibilityChangedListenerTest::TearDownTestCase(void) +{} + +void WindowVisibilityChangedListenerTest::SetUp() +{} + +void WindowVisibilityChangedListenerTest::TearDown() +{} + +/** + * @tc.name: WindowVisibilityChangedListener_OnWindowVisibilityChanged_0100 + * @tc.desc: Test the state of OnWindowVisibilityChanged + * @tc.type: FUNC + */ +HWTEST_F(WindowVisibilityChangedListenerTest, OnWindowVisibilityChanged_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0100 called start."); + std::weak_ptr abilitymgr; + std::shared_ptr handler; + auto Info = std::make_shared(abilitymgr, handler); + std::vector> windowVisibilityInfos; + Info->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_EQ(windowVisibilityInfos.empty(), true); + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0100 called end."); +} + +/** + * @tc.name: WindowVisibilityChangedListener_OnWindowVisibilityChanged_0200 + * @tc.desc: Test the state of OnWindowVisibilityChanged + * @tc.type: FUNC + */ +HWTEST_F(WindowVisibilityChangedListenerTest, OnWindowVisibilityChanged_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0200 called start."); + std::weak_ptr abilitymgr; + std::shared_ptr handler; + auto Info = std::make_shared(abilitymgr, handler); + std::vector> windowVisibilityInfos; + auto infos = new (std::nothrow) Rosen::WindowVisibilityInfo(); + EXPECT_NE(infos, nullptr); + infos->windowId_ = WINDOW_ID; + infos->pid_ = PID; + infos->visibilityState_ = Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION; + windowVisibilityInfos.push_back(infos); + Info->taskHandler_ = nullptr; + Info->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_EQ(Info->taskHandler_, nullptr); + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0200 called end."); +} + +/** + * @tc.name: WindowVisibilityChangedListener_OnWindowVisibilityChanged_0300 + * @tc.desc: Test the state of OnWindowVisibilityChanged + * @tc.type: FUNC + */ +HWTEST_F(WindowVisibilityChangedListenerTest, OnWindowVisibilityChanged_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0300 called start."); + std::weak_ptr abilitymgr; + std::shared_ptr handler = + AAFwk::TaskHandlerWrap::CreateQueueHandler("WindowVisibilityChangedListenerTest"); + auto Info = std::make_shared(abilitymgr, handler); + std::vector> windowVisibilityInfos; + auto infos = new (std::nothrow) Rosen::WindowVisibilityInfo(); + EXPECT_NE(infos, nullptr); + infos->windowId_ = WINDOW_ID; + infos->pid_ = PID; + infos->visibilityState_ = Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION; + windowVisibilityInfos.push_back(infos); + Info->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_NE(Info->taskHandler_, nullptr); + TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0300 called end."); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp b/test/unittest/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp index 00fb44ed905..d00c1c6fd3f 100644 --- a/test/unittest/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp +++ b/test/unittest/window_visibility_changed_listener_test/window_visibility_changed_listener_test.cpp @@ -126,6 +126,5 @@ HWTEST_F(WindowVisibilityChangedListenerTest, OnWindowVisibilityChanged_0300, Te EXPECT_NE(Info->taskHandler_, nullptr); TAG_LOGI(AAFwkTag::TEST, "OnWindowVisibilityChanged_0300 called end."); } - } // namespace AppExecFwk } // namespace OHOS -- Gitee