From b39e2db02566549fe12748a561920187340dbe06 Mon Sep 17 00:00:00 2001 From: happy Date: Fri, 30 May 2025 23:18:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E8=A7=86=E9=A2=91=E5=86=99=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E8=BE=93=E5=85=A5=E6=96=87=E5=AD=97=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E4=B8=8E=E8=83=8C=E6=99=AF=E8=89=B2=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: happy Change-Id: I9001159ba3d41106a780e7bedc0052569693d669 --- .../components/theme/theme_manager_impl.cpp | 19 ------ test/unittest/core/manager/BUILD.gn | 14 ++++ .../core/manager/theme_manager_test_ng.cpp | 64 +++++++++++++++++++ 3 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 test/unittest/core/manager/theme_manager_test_ng.cpp diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index 5ca081a64e1..850a2b76961 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -245,25 +245,6 @@ RefPtr ThemeManagerImpl::GetThemeOrigin(ThemeType type) return nullptr; } - if (auto pipelineContext = NG::PipelineContext::GetCurrentContext(); pipelineContext) { - ColorMode localMode = pipelineContext->GetLocalColorMode(); - ColorMode systemMode = pipelineContext->GetColorMode(); - bool needRestore = false; - if (localMode != ColorMode::COLOR_MODE_UNDEFINED && localMode != systemMode) { - // Ordinary themes should work in system color mode. Only theme wrappers support local color mode. - ResourceManager::GetInstance().UpdateColorMode(systemMode); - pipelineContext->SetLocalColorMode(ColorMode::COLOR_MODE_UNDEFINED); - needRestore = true; - } - auto theme = builderIter->second(themeConstants_); - if (needRestore) { - pipelineContext->SetLocalColorMode(localMode); - ResourceManager::GetInstance().UpdateColorMode(localMode); - } - themes_.emplace(type, theme); - return theme; - } - auto theme = builderIter->second(themeConstants_); themes_.emplace(type, theme); return theme; diff --git a/test/unittest/core/manager/BUILD.gn b/test/unittest/core/manager/BUILD.gn index c1602b83b1f..e7266ed642c 100644 --- a/test/unittest/core/manager/BUILD.gn +++ b/test/unittest/core/manager/BUILD.gn @@ -153,6 +153,19 @@ ace_unittest("drag_drop_behavior_reporter_test_ng") { sources = [ "./drag_drop/drag_drop_behavior_reporter_test_ng.cpp" ] } +ace_unittest("theme_manager_test_ng") { + type = "new" + module_output = "manager" + sources = [ + "$ace_root/frameworks/core/components/checkable/checkable_theme.cpp", + "$ace_root/frameworks/core/components/dialog/dialog_theme.cpp", + "$ace_root/frameworks/core/components/picker/picker_theme.cpp", + "$ace_root/frameworks/core/components/theme/app_theme.cpp", + "$ace_root/frameworks/core/components/theme/theme_manager_impl.cpp", + "theme_manager_test_ng.cpp", + ] +} + group("core_manager_unittest") { testonly = true deps = [ @@ -176,5 +189,6 @@ group("core_manager_unittest") { ":select_overlay_manager_test_ng", ":select_overlay_proxy_test_ng", ":shared_overlay_manager_test_ng", + ":theme_manager_test_ng", ] } diff --git a/test/unittest/core/manager/theme_manager_test_ng.cpp b/test/unittest/core/manager/theme_manager_test_ng.cpp new file mode 100644 index 00000000000..38490513198 --- /dev/null +++ b/test/unittest/core/manager/theme_manager_test_ng.cpp @@ -0,0 +1,64 @@ +/* + * 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 "gtest/gtest.h" +#define private public +#define protected public + +#include "test/mock/core/common/mock_container.h" +#include "test/mock/core/pipeline/mock_pipeline_context.h" + +#include "frameworks/core/components/theme/theme_manager_impl.h" +#include "core/components/button/button_theme.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS::Ace::NG { + +class ThemeManagerTestNg : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); +}; + +void ThemeManagerTestNg::SetUpTestCase() +{ + MockPipelineContext::SetUp(); + MockContainer::SetUp(); +} + +void ThemeManagerTestNg::TearDownTestCase() +{ + MockPipelineContext::TearDown(); + MockContainer::TearDown(); +} + +/** + * @tc.name: ThemeMangerTestNg001 + * @tc.desc: GetThemeOrigin + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTestNg, ThemeManagerTestNg001, TestSize.Level1) +{ + /** + * @tc.steps: create themeManager + */ + auto themeManager = AceType::MakeRefPtr(); + auto theme = themeManager->GetThemeOrigin(ButtonTheme::TypeId()); + EXPECT_TRUE(AceType::InstanceOf(theme)); +} +} -- Gitee