diff --git a/adapter/ohos/entrance/ace_container.h b/adapter/ohos/entrance/ace_container.h index b63e6222812bc1d453e1c998c72c3aa9d3a3d4df..407a8f174b97d892fb2dbd689c341fb3d4374f1e 100644 --- a/adapter/ohos/entrance/ace_container.h +++ b/adapter/ohos/entrance/ace_container.h @@ -588,7 +588,7 @@ public: ResourceConfiguration& resConfig, ConfigurationChange& configurationChange, const ParsedConfig& parsedConfig); void UpdateConfiguration( const ParsedConfig& parsedConfig, const std::string& configuration, bool abilityLevel = false); - void UpdateConfigurationSyncForAll( + virtual void UpdateConfigurationSyncForAll( const ParsedConfig& parsedConfig, const std::string& configuration); void NotifyConfigurationChange( diff --git a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp index 2c0ba6ca094916d814fccf50e402fca690e9fb07..bbf6ab16c6195ef89979ad7c3c7892b537bc65ad 100644 --- a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp +++ b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp @@ -303,6 +303,7 @@ void SubwindowOhos::InitContainer() window_->RegisterWindowAttachStateChangeListener(new MenuWindowSceneListener(WeakClaim(this))); window_->SetFollowScreenChange(needFollowScreen); defaultDisplayId_ = displayId; + window_->SetSubWindowSource(Rosen::SubWindowSource::SUB_WINDOW_SOURCE_ARKUI); } std::string url = ""; auto subSurface = window_->GetSurfaceNode(); @@ -1464,6 +1465,7 @@ bool SubwindowOhos::InitToastDialogWindow(int32_t& width, int32_t& height, int32 } CHECK_NULL_RETURN(dialogWindow_, false); dialogWindow_->SetLayoutFullScreen(true); + dialogWindow_->SetSubWindowSource(Rosen::SubWindowSource::SUB_WINDOW_SOURCE_ARKUI); auto focusWindowId = dialogWindow_->GetDisplayId(); auto focusDisplayInfo = Rosen::DisplayManager::GetInstance().GetDisplayById(focusWindowId); CHECK_NULL_RETURN(focusDisplayInfo, false); diff --git a/adapter/ohos/entrance/ui_content_impl.h b/adapter/ohos/entrance/ui_content_impl.h index 704d17abab6eaf7fbac9e3ec26b33a382d240e26..3159d33e0706983006be6b63e11bcb95134d14ad 100644 --- a/adapter/ohos/entrance/ui_content_impl.h +++ b/adapter/ohos/entrance/ui_content_impl.h @@ -427,6 +427,10 @@ public: // intent framework void SetIntentParam(const std::string& intentInfoSerialized, const std::function&& loadPageCallback, bool isColdStart) override; +#ifdef ACE_UNITTEST + void SetInstanceId(int32_t instanceId) { instanceId_ = instanceId; } +#endif + private: UIContentErrorCode InitializeInner( OHOS::Rosen::Window* window, const std::string& contentInfo, napi_value storage, bool isNamedRouter); diff --git a/test/mock/adapter/mock_ace_container.cpp b/test/mock/adapter/mock_ace_container.cpp index 2dbd15ff31e61c7a9f5a6298c4fcd98e273cda3d..92e918c650e148b6933d90d904b32baf47681ab2 100644 --- a/test/mock/adapter/mock_ace_container.cpp +++ b/test/mock/adapter/mock_ace_container.cpp @@ -84,4 +84,110 @@ void AceContainer::DispatchExtensionDataToHostWindow( } void AceContainer::UpdateColorMode(uint32_t colorMode) {} + +void AceContainer::Initialize() {} + +void AceContainer::Destroy() {} + +bool AceContainer::IsKeyboard() { return false; } + +void AceContainer::DestroyView() {} + +bool AceContainer::UpdatePopupUIExtension(const RefPtr& node, uint32_t autoFillSessionId, bool isNative) +{ + return false; +} + +bool AceContainer::ClosePopupUIExtension(uint32_t autoFillSessionId) +{ + return false; +} + +HintToTypeWrap AceContainer::PlaceHolderToType(const std::string& onePlaceHolder) +{ + return {}; +} + +bool AceContainer::Dump(const std::vector& params, std::vector& info) +{ + return true; +} + +void AceContainer::TriggerGarbageCollection() {} + +void AceContainer::DumpHeapSnapshot(bool isPrivate) {} + +void AceContainer::DestroyHeapProfiler() {} + +void AceContainer::ForceFullGC() {} + +NG::SafeAreaInsets AceContainer::GetKeyboardSafeArea() +{ + return {}; +} + +bool AceContainer::IsMainWindow() const { return true; } +bool AceContainer::IsSubWindow() const { return false; } +bool AceContainer::IsDialogWindow() const { return false; } +bool AceContainer::IsSystemWindow() const { return false; } +bool AceContainer::IsHostMainWindow() const { return false; } +bool AceContainer::IsHostSubWindow() const { return false; } +bool AceContainer::IsHostDialogWindow() const { return false; } +bool AceContainer::IsHostSystemWindow() const { return false; } +bool AceContainer::IsHostSceneBoardWindow() const { return false; } + +uint32_t AceContainer::GetParentMainWindowId(uint32_t currentWindowId) const { return 0; } +void AceContainer::NotifyConfigurationChange + (bool needReloadTransition, const ConfigurationChange& configurationChange) {} +void AceContainer::HotReload() {} +bool AceContainer::IsLauncherContainer() { return false; } +bool AceContainer::IsSceneBoardWindow() { return false; } +bool AceContainer::IsUIExtensionWindow() { return false; } +bool AceContainer::IsSceneBoardEnabled() { return false; } + +bool AceContainer::GetCurPointerEventSourceType(int32_t& sourceType) { return false; } + +int32_t AceContainer::RequestAutoFill( + const RefPtr& node, AceAutoFillType autoFillType, bool isNewPassWord, + bool& isPopup, uint32_t& autoFillSessionId, bool isNative, + const std::function& onFinish, + const std::function& onUIExtNodeBindingCompleted) +{ + return 0; +} +bool AceContainer::IsNeedToCreatePopupWindow(const AceAutoFillType& autoFillType) { return false; } +bool AceContainer::RequestAutoSave(const RefPtr& node, const std::function& onFinish, + const std::function& onUIExtNodeBindingCompleted, bool isNative, + int32_t instanceId) +{ + return false; +} +std::shared_ptr AceContainer::GetNavigationController(const std::string& navigationId) +{ + return std::shared_ptr(); +} +void AceContainer::TerminateUIExtension() {} +void AceContainer::RequestAtomicServiceTerminate() {} +bool AceContainer::UIExtensionIsHalfScreen() { return false; } +void AceContainer::CheckAndSetFontFamily() {} +bool AceContainer::GetLastMovingPointerPosition(DragPointerEvent& dragPointerEvent) { return false; } + +void AceContainer::Dispatch( + const std::string& group, std::vector&& data, int32_t id, bool replyToComponent) const +{} + +void AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const +{} + +bool AceContainer::MaybeRelease() { return false; } + +bool AceContainer::GetCurPointerEventInfo(DragPointerEvent& dragPointerEvent, StopDragCallback&& stopDragCallback) +{ + return false; +} + +AceContainer::AceContainer(int, OHOS::Ace::FrontendType) {} +AceContainer::~AceContainer() {} + +void AceContainer::UpdateConfigurationSyncForAll(const ParsedConfig& parsedConfig, const std::string& configuration) {} } // namespace OHOS::Ace::Platform diff --git a/test/mock/core/common/mock_dialog_container.h b/test/mock/core/common/mock_dialog_container.h new file mode 100644 index 0000000000000000000000000000000000000000..b4e8d58d6ed1f7f29aa1906f513263676d515eb2 --- /dev/null +++ b/test/mock/core/common/mock_dialog_container.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_DIALOG_CONTAINER_H +#define FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_DIALOG_CONTAINER_H + +#include "gmock/gmock.h" + +#include "adapter/ohos/entrance/ace_container.h" + +namespace OHOS::Ace { +class MockDialogContainer final : public Platform::AceContainer { + DECLARE_ACE_TYPE(MockDialogContainer, AceContainer); + +public: + explicit MockDialogContainer(int32_t instanceId, FrontendType type) : AceContainer(instanceId, type) {} + + bool IsDialogContainer() const override + { + return isDialogContainer_; + } + + void UpdateConfigurationSyncForAll( + const Platform::ParsedConfig& parsedConfig, const std::string& configuration) + { + updateConfigurationSyncForAll_ = true; + } + + void SetDialogContainer(bool isDialogContainer) + { + isDialogContainer_ = isDialogContainer; + } + + bool CheckUpdateConfigurationSyncForAll() + { + return updateConfigurationSyncForAll_; + } + +private: + bool updateConfigurationSyncForAll_ = false; + bool isDialogContainer_ = true; +}; +} // namespace OHOS::Ace +#endif // FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_DIALOG_CONTAINER_H diff --git a/test/unittest/interfaces/BUILD.gn b/test/unittest/interfaces/BUILD.gn index ecabcce51e96e58401bd58f474285d147b33375d..f312bb7a526a238495552ff15b2632386238b4ae 100644 --- a/test/unittest/interfaces/BUILD.gn +++ b/test/unittest/interfaces/BUILD.gn @@ -27,7 +27,10 @@ ohos_unittest("ui_content_test") { sources = [ "$ace_root/frameworks/core/common/container_scope.cpp", "$ace_root/interfaces/inner_api/ace/ui_content.cpp", + "$ace_root/test/mock/adapter/mock_ace_container.cpp", "$ace_root/test/mock/base/mock_lifecycle_checkable.cpp", + "$ace_root/test/mock/core/common/mock_ace_engine.cpp", + "$ace_root/test/mock/core/common/mock_container.cpp", "ui_content_test.cpp", ] diff --git a/test/unittest/interfaces/ui_content_test.cpp b/test/unittest/interfaces/ui_content_test.cpp index 58f187e034b0a37e5ba9bd752ba91ada0ff41418..cccf3846163095c96b55c86a69f496888bafee99 100644 --- a/test/unittest/interfaces/ui_content_test.cpp +++ b/test/unittest/interfaces/ui_content_test.cpp @@ -15,9 +15,12 @@ #include "ability_context.h" #include "ability_info.h" +#include "adapter/ohos/entrance/ui_content_impl.h" #include "context_impl.h" +#include "frameworks/core/common/ace_engine.h" #include "gtest/gtest.h" #include "interfaces/inner_api/ace/ui_content.h" +#include "test/mock/core/common/mock_dialog_container.h" using namespace testing; using namespace testing::ext; @@ -53,4 +56,31 @@ HWTEST_F(UiContentTest, GetUIContent001, TestSize.Level1) std::string ret2 = UIContent::GetCurrentUIStackInfo(); EXPECT_TRUE(ret2 == std::string()); } + +/** + * @tc.name: UpdateConfigurationUIContent001 + * @tc.desc: test UpdateConfigurationSyncForAll + * @tc.type: FUNC + */ +HWTEST_F(UiContentTest, UpdateConfigurationUIContent001, TestSize.Level1) +{ + OHOS::AppExecFwk::Ability* ability = nullptr; + std::unique_ptr uiContent = UIContent::Create(ability); + EXPECT_TRUE(uiContent.get() != nullptr); + + UIContentImpl* uiContentImpl = static_cast(uiContent.get()); + int32_t instanceId = 1; + auto dialogContainer = + AceType::MakeRefPtr(instanceId, FrontendType::DECLARATIVE_JS); + AceEngine::Get().AddContainer(instanceId, dialogContainer); + uiContentImpl->SetInstanceId(instanceId); + + std::shared_ptr config; + uiContentImpl->UpdateConfigurationSyncForAll(config); + EXPECT_FALSE(dialogContainer->CheckUpdateConfigurationSyncForAll()); + + dialogContainer->SetDialogContainer(false); + uiContentImpl->UpdateConfigurationSyncForAll(config); + EXPECT_TRUE(dialogContainer->CheckUpdateConfigurationSyncForAll()); +} } // namespace OHOS::Ace \ No newline at end of file