fix differences 6

Signed-off-by: WangYing225 <wangying397@huawei.com>
Change-Id: Idaf348cf10ab15b9690b5ef3c10024e99d3a4f2b
This commit is contained in:
WangYing225 2024-07-30 15:42:53 +08:00
parent b20a5d0b51
commit b8ea90854f
17 changed files with 275 additions and 295 deletions

View File

@ -21,13 +21,14 @@
#include "core/common/container.h"
#include "core/components/video/video_utils.h"
#include "core/components_ng/render/adapter/render_surface_impl.h"
#ifdef RENDER_EXTRACT_SUPPORTED
#include "core/components_ng/render/adapter/render_texture_impl.h"
#endif
#include "core/pipeline_ng/pipeline_context.h"
namespace OHOS::Ace::NG {
namespace {
constexpr int32_t SECONDS_TO_MILLISECONDS = 1000;
} // namespace
MediaPlayerImpl::~MediaPlayerImpl()
@ -92,6 +93,11 @@ void MediaPlayerImpl::InitListener()
if (player->stateChangeCallback_) {
player->stateChangeCallback_(isPlaying ? PlaybackStatus::STARTED : PlaybackStatus::PAUSED);
}
#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
if (player->startRenderFrameCallback_ && isPlaying) {
player->startRenderFrameCallback_();
}
#endif
}, "ArkUIVideoPlayerStatusChanged");
};
@ -144,8 +150,18 @@ bool MediaPlayerImpl::SetSource(const std::string& src)
void MediaPlayerImpl::SetRenderSurface(const RefPtr<RenderSurface>& renderSurface)
{
renderSurface_ = renderSurface;
#ifdef RENDER_EXTRACT_SUPPORTED
if (renderSurface ->IsTexture()) {
auto surfaceImpl = AceType::DynamicCast<RenderTextureImpl>(renderSurface);
surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this));
} else {
auto surfaceImpl = AceType::DynamicCast<RenderSurfaceImpl>(renderSurface);
surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this));
}
#else
auto surfaceImpl = AceType::DynamicCast<RenderSurfaceImpl>(renderSurface);
surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this));
#endif
}
void MediaPlayerImpl::RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent,
@ -159,6 +175,11 @@ void MediaPlayerImpl::RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUp
startRenderFrameCallback_ = startRenderFrameEvent;
}
void MediaPlayerImpl::RegisterTextureEvent(TextureRefreshEnVent&& textureRefreshEvent)
{
textureRefreshCallback_ = textureRefreshEvent;
}
int32_t MediaPlayerImpl::GetDuration(int32_t& duration)
{
CHECK_NULL_RETURN(player_, -1);
@ -195,9 +216,23 @@ int32_t MediaPlayerImpl::SetPlaybackSpeed(float speed)
int32_t MediaPlayerImpl::SetSurface()
{
CHECK_NULL_RETURN(player_, -1);
auto surfaceImpl = AceType::DynamicCast<RenderSurfaceImpl>(renderSurface_.Upgrade());
auto renderSurface = renderSurface_.Upgrade();
CHECK_NULL_RETURN(renderSurface, -1);
#ifdef RENDER_EXTRACT_SUPPORTED
if (renderSurface ->IsTexture()) {
auto textureImpl = AceType::DynamicCast<RenderTextureImpl>(renderSurface);
CHECK_NULL_RETURN(textureImpl, -1);
player_->SetSurfaceId(textureImpl->GetTextureId(), true);
} else {
auto surfaceImpl = AceType::DynamicCast<RenderSurfaceImpl>(renderSurface);
CHECK_NULL_RETURN(surfaceImpl, -1);
player_->SetSurfaceId(surfaceImpl->GetSurfaceId(), false);
}
#else
auto surfaceImpl = AceType::DynamicCast<RenderSurfaceImpl>(renderSurface);
CHECK_NULL_RETURN(surfaceImpl, -1);
player_->SetSurfaceId(surfaceImpl->GetSurfaceId());
player_->SetSurfaceId(surfaceImpl->GetSurfaceId(), false);
#endif
return 0;
}
@ -266,4 +301,11 @@ void MediaPlayerImpl::ProcessSurfaceChange(int32_t width, int32_t height)
}
}
} // namespace OHOS::Ace::NG
void MediaPlayerImpl::ProcessTextureRefresh(int32_t instanceId, int64_t textureId)
{
if (textureRefreshCallback_) {
textureRefreshCallback_(instanceId, textureId);
}
}
} // namespace OHOS::Ace::NG

View File

@ -37,6 +37,7 @@ public:
void SetRenderSurface(const RefPtr<RenderSurface>& renderSurface) override;
void RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent, StateChangedEvent&& stateChangedEvent,
CommonEvent&& errorEvent, CommonEvent&& resolutionChangeEvent, CommonEvent&& startRenderFrameEvent) override;
void RegisterTextureEvent(TextureRefreshEnVent&& textureRefreshEvent) override;
int32_t GetDuration(int32_t& duration) override;
int32_t GetVideoWidth() override;
int32_t GetVideoHeight() override;
@ -54,6 +55,7 @@ public:
void ProcessSurfaceCreate() override;
void ProcessSurfaceChange(int32_t width, int32_t height) override;
void ProcessSurfaceDestroy() override {}
void ProcessTextureRefresh(int32_t instanceId, int64_t textureId) override;
private:
void InitListener();
@ -65,6 +67,7 @@ private:
CommonEvent errorCallback_;
CommonEvent resolutionChangeCallback_;
CommonEvent startRenderFrameCallback_;
TextureRefreshEnVent textureRefreshCallback_;
ACE_DISALLOW_COPY_AND_MOVE(MediaPlayerImpl);
};

View File

@ -38,7 +38,7 @@ const uint32_t ADJUST_WEB_DRAW_LENGTH = 3000;
const uint32_t DEFAULT_WEB_DRAW_LENGTH = 6167;
const std::string SURFACE_WIDTH = "surface_width";
const std::string SURFACE_HEIGHT = "surface_height";
const int32_t SIZE_LIMIT = 5999;
const int32_t SIZE_LIMIT = 7999;
const int32_t PERMITTED_DIFFERENCE = 100;
const int32_t FAILED_LIMIT = 3;
@ -320,8 +320,6 @@ bool RosenRenderSurface::CompareBufferSize(int32_t width, int32_t height,
failTimes_++;
if (failTimes_ <= FAILED_LIMIT) {
pipeline->SetIsFreezeFlushMessage(true);
ACE_SCOPED_TRACE("Web SetIsFreezeFlushMessage (width %d, height %d, bufferWidth %d, bufferHeight %d)",
width, height, bufferWidth, bufferHeight);
return false;
}
}

View File

@ -33,21 +33,8 @@ class ACE_FORCE_EXPORT RenderSurface : public virtual AceType {
public:
RenderSurface() = default;
~RenderSurface() override = default;
// under the condition of supporting cross platform and texture rendering,
// it is necessary to dynamically set the rendering type of the surface node.
// the defalut type is RenderSurfaceType::TEXTURE.
#ifdef RENDER_EXTRACT_SUPPORTED
enum class RenderSurfaceType {
UNKNOWN = -1,
SURFACE = 0,
TEXTURE
};
static RefPtr<RenderSurface> Create(const RenderSurfaceType& type = RenderSurfaceType::TEXTURE);
#else
// under the condition of supporting ohos platform
static RefPtr<RenderSurface> Create();
#endif
virtual void InitSurface() {}
@ -80,11 +67,6 @@ public:
virtual void SetExtSurfaceBounds(int32_t left, int32_t top, int32_t width, int32_t height) {}
virtual bool SetExtSurfaceBoundsSync(int32_t left, int32_t top, int32_t width, int32_t height)
{
return true;
}
virtual void SetExtSurfaceCallback(const RefPtr<ExtSurfaceCallbackInterface>& extSurfaceCallback) {}
virtual void SetTransformHint(uint32_t rotation) {}
@ -99,15 +81,6 @@ public:
virtual void SetSurfaceDefaultSize(int32_t width, int32_t height) {}
virtual bool IsTexture()
{
return false;
}
virtual void AttachToGLContext(int64_t textureId, bool isAttach) {}
virtual void UpdateTextureImage(std::vector<float>& matrix) {}
virtual void SetWebMessage(OffsetF offset) {}
virtual void SetWebSlideAxis(Axis axis) {}

View File

@ -16,39 +16,19 @@
#if defined(ENABLE_ROSEN_BACKEND) && defined(OHOS_PLATFORM)
#include "core/components_ng/render/adapter/rosen_render_surface.h"
#endif
#ifdef RENDER_EXTRACT_SUPPORTED
#include "core/components_ng/render/adapter/render_texture_impl.h"
#endif
#include "core/components_ng/render/adapter/render_surface_impl.h"
#include "core/components_ng/render/render_surface.h"
namespace OHOS::Ace::NG {
// under the condition of supporting cross platform and texture rendering
#ifdef RENDER_EXTRACT_SUPPORTED
RefPtr<RenderSurface> RenderSurface::Create(const RenderSurfaceTpye& type)
{
if (SystemProperties::GetRosenBackendEnabled()) {
switch (type) {
case RenderSurfaceTpye::SURFACE:
return MakeRefPtr<RenderSurfaceImpl>();
case RenderSurfaceTpye::TEXTURE:
return MakeRefPtr<RenderTextureImpl>();
default:
break;
}
}
return MakeRefPtr<RenderSurface>();
}
#else
// under the condition of supporting ohos platform
RefPtr<RenderSurface> RenderSurface::Create()
{
if (SystemProperties::GetRosenBackendEnabled()) {
#if defined(OHOS_PLATFORM) && defined(ENABLE_ROSEN_BACKEND)
return MakeRefPtr<RosenRenderSurface>();
#else
return MakeRefPtr<RenderSurfaceImpl>();
#endif
}
return MakeRefPtr<RenderSurface>();
}
#endif
} // namespace OHOS::Ace::NG

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2023-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2023-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

View File

@ -29,10 +29,9 @@ std::string g_strValue;
void SetXComponentBackgroundColor(ArkUINodeHandle node, uint32_t color)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
auto *frameNode = reinterpret_cast<FrameNode *>(node);
CHECK_NULL_VOID(frameNode);
auto type = XComponentModelNG::GetType(frameNode);
if (!XComponentModel::IsBackGroundColorAvailable(type)) {
if (!XComponentModelNG::IsTexture(frameNode)) {
return;
}
ViewAbstract::SetBackgroundColor(frameNode, Color(color));
@ -40,13 +39,12 @@ void SetXComponentBackgroundColor(ArkUINodeHandle node, uint32_t color)
void ResetXComponentBackgroundColor(ArkUINodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
auto *frameNode = reinterpret_cast<FrameNode *>(node);
CHECK_NULL_VOID(frameNode);
auto type = XComponentModelNG::GetType(frameNode);
if (!XComponentModel::IsBackGroundColorAvailable(type)) {
if (!XComponentModelNG::IsTexture(frameNode)) {
return;
}
ViewAbstract::SetBackgroundColor(frameNode, (type == XComponentType::SURFACE) ? Color::BLACK : Color::TRANSPARENT);
ViewAbstract::SetBackgroundColor(frameNode, Color(Color::TRANSPARENT));
}
void SetXComponentOpacity(ArkUINodeHandle node, ArkUI_Float32 opacity)

View File

@ -284,24 +284,6 @@ int32_t OH_NativeXComponent_DetachNativeRootNode(
return component->DetachNativeRootNode(root->uiNodeHandle);
}
int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
ArkUI_UIInputEvent_Type type)
{
if ((component == nullptr) || (callback == nullptr)) {
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
}
if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) {
return component->RegisterUIAxisEventCallback(callback);
}
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
}
int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard)
{
return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
}
int32_t OH_NativeXComponent_RegisterSurfaceShowCallback(
OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
{
@ -316,6 +298,19 @@ int32_t OH_NativeXComponent_RegisterSurfaceHideCallback(
: OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
}
int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
ArkUI_UIInputEvent_Type type)
{
if ((component == nullptr) || (callback == nullptr)) {
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
}
if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) {
return component->RegisterUIAxisEventCallback(callback);
}
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
}
int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback(
OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event))
{
@ -325,6 +320,11 @@ int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback(
return component->RegisterOnTouchInterceptCallback(callback);
}
int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard)
{
return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
}
int32_t OH_NativeXComponent_GetTouchEventSourceType(
OH_NativeXComponent* component, int32_t pointId, OH_NativeXComponent_EventSourceType* sourceType)
{

View File

@ -715,32 +715,6 @@ int32_t OH_NativeXComponent_AttachNativeRootNode(OH_NativeXComponent* component,
*/
int32_t OH_NativeXComponent_DetachNativeRootNode(OH_NativeXComponent* component, ArkUI_NodeHandle root);
/**
* @brief Registers a UI input event callback for this <b>OH_NativeXComponent</b> instance and enables the callback to
* be invoked when a UI input event is received.
*
* @param component Indicates the pointer to the <b>OH_NativeXComponent</b> instance.
* @param callback Indicates the pointer to the UI input event callback.
* @param type Indicates the type of the current UI input event.
* @return Returns 0 if success.
* Returns 401 if a parameter exception occurs.
* @since 12
*/
int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
ArkUI_UIInputEvent_Type type);
/**
* @brief Set whether the <b>OH_NativeXComponent</b> instance needs soft keyboard.
* @param component Indicates the pointer to this <b>OH_NativeXComponent</b> instance.
* @param needSoftKeyboard Indicates whether the <b>OH_NativeXComponent</b> instance needs soft keyboard or not.
* Default value is false.
* @return Returns the status code of the execution.
* @since 12
* @version 1.0
*/
int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard);
/**
* @brief Registers a callback for this <b>OH_NativeXComponent</b> instance.
*
@ -765,6 +739,21 @@ int32_t OH_NativeXComponent_RegisterSurfaceShowCallback(
int32_t OH_NativeXComponent_RegisterSurfaceHideCallback(
OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window));
/**
* @brief Registers a UI input event callback for this <b>OH_NativeXComponent</b> instance and enables the callback to
* be invoked when a UI input event is received.
*
* @param component Indicates the pointer to the <b>OH_NativeXComponent</b> instance.
* @param callback Indicates the pointer to the UI input event callback.
* @param type Indicates the type of the current UI input event.
* @return Returns 0 if success.
* Returns 401 if a parameter exception occurs.
* @since 12
*/
int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
ArkUI_UIInputEvent_Type type);
/**
* @brief Registers a callback for this <b>OH_NativeXComponent</b> instance.
*
@ -777,6 +766,17 @@ int32_t OH_NativeXComponent_RegisterSurfaceHideCallback(
int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback(
OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event));
/**
* @brief Set whether the <b>OH_NativeXComponent</b> instance needs soft keyboard.
* @param component Indicates the pointer to this <b>OH_NativeXComponent</b> instance.
* @param needSoftKeyboard Indicates whether the <b>OH_NativeXComponent</b> instance needs soft keyboard or not.
* Default value is false.
* @return Returns the status code of the execution.
* @since 12
* @version 1.0
*/
int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard);
/**
* @brief Obtains the touch event's source type dispatched by the ArkUI XComponent.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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

View File

@ -27,9 +27,9 @@ public:
~MockRenderSurface() override = default;
MOCK_CONST_METHOD0(IsSurfaceValid, bool());
MOCK_METHOD2(AdjustNativeWindowSize, void(uint32_t, uint32_t));
MOCK_METHOD0(ReleaseSurfaceBuffers, void());
MOCK_METHOD2(ConfigSurface, void(uint32_t, uint32_t));
MOCK_METHOD4(SetExtSurfaceBounds, void(int32_t, int32_t, int32_t, int32_t));
MOCK_METHOD0(ReleaseSurfaceBuffers, void());
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_SURFACE_H

View File

@ -1,4 +1,4 @@
# Copyright (c) 2024-2025 Huawei Device Co., Ltd.
# 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* 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

View File

@ -20,11 +20,10 @@ namespace OHOS::Ace {
void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const AlignDirection& direction,
const HorizontalAlign& horizontalRule, std::map<AlignDirection, AlignRule>& alignRules)
{
auto alignDirection = AlignDirectionRtl(direction);
AlignRule alignRule;
alignRule.anchor = id;
alignRule.horizontal = horizontalRule;
alignRules[alignDirection] = alignRule;
alignRules[direction] = alignRule;
}
void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const AlignDirection& direction,
@ -35,15 +34,4 @@ void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const Ali
alignRule.vertical = verticalRule;
alignRules[direction] = alignRule;
}
AlignDirection RelativeContainerTestUtilsNG::AlignDirectionRtl(const AlignDirection& direction)
{
if (direction == AlignDirection::START) {
return AlignDirection::LEFT;
} else if (direction == AlignDirection::END) {
return AlignDirection::RIGHT;
} else {
return direction;
}
}
} // namespace OHOS::Ace

View File

@ -28,7 +28,6 @@ public:
const HorizontalAlign& horizontalRule, std::map<AlignDirection, AlignRule>& alignRules);
static void AddAlignRule(const std::string& id, const AlignDirection& direction, const VerticalAlign& verticalRule,
std::map<AlignDirection, AlignRule>& alignRules);
static AlignDirection AlignDirectionRtl(const AlignDirection& direction);
};
} // namespace OHOS::Ace

View File

@ -82,11 +82,11 @@ const float CHILD_OFFSET_HEIGHT = 0.0f;
const float FORCE = 3.0f;
TestProperty testProperty;
bool isFocus = false;
int g_surfaceShowNum = 1;
const float SURFACE_WIDTH = 250.0f;
const float SURFACE_HEIGHT = 150.0f;
const float SURFACE_OFFSETX = 10.0f;
const float SURFACE_OFFSETY = 20.0f;
int g_surfaceShowNum = 1;
bool isAxis = false;
bool isLock = true;
@ -588,6 +588,135 @@ HWTEST_F(XComponentTestNg, XComponentTextureTypeTest011, TestSize.Level1)
pattern->InitNativeWindow(MAX_WIDTH, MAX_HEIGHT);
}
/**
* @tc.name: XComponentControllerTest
* @tc.desc: Test XComponentController's interface
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentControllerTest, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE_VALUE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
EXPECT_TRUE(frameNode);
EXPECT_EQ(frameNode->GetTag(), V2::XCOMPONENT_ETS_TAG);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
pattern->hasXComponentInit_ = true;
EXPECT_EQ(pattern->type_, XCOMPONENT_SURFACE_TYPE_VALUE);
EXPECT_TRUE(pattern->IsAtomicNode());
auto renderContext = AceType::MakeRefPtr<MockRenderContext>();
pattern->handlingSurfaceRenderContext_ = renderContext;
/**
* @tc.steps: step2. call XcomponentController's interface releative to SetSurfaceRect
* @tc.expected: handlingSurfaceRenderContext_->SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY,
* SURFACE_WIDTH, SURFACE_HEIGHT) is called
*/
auto xcomponentController = pattern->xcomponentController_;
EXPECT_TRUE(xcomponentController);
pattern->drawSize_ = MAX_SIZE;
xcomponentController->SetIdealSurfaceWidth(SURFACE_WIDTH);
xcomponentController->SetIdealSurfaceHeight(SURFACE_HEIGHT);
xcomponentController->SetIdealSurfaceOffsetX(SURFACE_OFFSETX);
xcomponentController->SetIdealSurfaceOffsetY(SURFACE_OFFSETY);
EXPECT_CALL(*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_),
SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, SURFACE_WIDTH, SURFACE_HEIGHT))
.WillOnce(Return());
xcomponentController->UpdateSurfaceBounds();
/**
* @tc.steps: step3. call XcomponentController's interface releative to GetSurfaceRect
* @tc.expected: the rect get from GetSurfaceRect equals the rect set by SetSurfaceRect
*/
auto surfaceWidth = 0.0f;
auto surfaceHeight = 0.0f;
auto surfaceOffsetX = 0.0f;
auto surfaceOffsetY = 0.0f;
xcomponentController->GetSurfaceSize(surfaceWidth, surfaceHeight);
xcomponentController->GetLocalLocation(surfaceOffsetX, surfaceOffsetY);
EXPECT_EQ(surfaceOffsetX, SURFACE_OFFSETX);
EXPECT_EQ(surfaceOffsetY, SURFACE_OFFSETY);
EXPECT_EQ(surfaceWidth, SURFACE_WIDTH);
EXPECT_EQ(surfaceHeight, SURFACE_HEIGHT);
/**
* @tc.steps: step4. call XcomponentController's ClearIdealSurfaceOffset
* @tc.expected: handlingSurfaceRenderContext_->SetBounds(newSurfaceOffsetX, newSurfaceOffsetY,
* SURFACE_WIDTH, SURFACE_HEIGHT) is called
*/
auto newSurfaceOffsetX = (MAX_WIDTH - SURFACE_WIDTH) / 2.0f;
auto newSurfaceOffsetY = (MAX_HEIGHT - SURFACE_HEIGHT) / 2.0f;
xcomponentController->ClearIdealSurfaceOffset(true);
xcomponentController->ClearIdealSurfaceOffset(false);
EXPECT_CALL(*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_),
SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, SURFACE_WIDTH, SURFACE_HEIGHT))
.WillOnce(Return());
xcomponentController->UpdateSurfaceBounds();
/**
* @tc.steps: step5. call XcomponentController's interface relative to SetSurfaceRotation
* @tc.expected: handlingSurfaceRenderContext_->SetSurfaceRotation(isLock) is called
*/
EXPECT_CALL(
*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_), SetSurfaceRotation(isLock))
.WillOnce(Return());
xcomponentController->SetSurfaceRotation(isLock);
/**
* @tc.steps: step6. call XcomponentController's interface relative to GetSurfaceRotation
* @tc.expected: the lock status get from GetSurfaceRotation equals the lock status set by SetSurfaceRotation
*/
auto lock = xcomponentController->GetSurfaceRotation();
EXPECT_EQ(lock, isLock);
}
/**
* @tc.name: XComponentAxisEventTest012
* @tc.desc: Test AxisEvent
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentAxisEventTest012, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
ASSERT_TRUE(frameNode);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
/**
* @tc.steps: step2. create nativeXComponent instance
* @tc.expected: focusHub & nativeXComponent instance create successfully
*/
auto pair = pattern->GetNativeXComponent();
auto weakNativeXComponent = pair.second;
auto nativeXComponent = weakNativeXComponent.lock();
auto nativeXComponentImpl = pair.first;
ASSERT_TRUE(nativeXComponent);
ASSERT_TRUE(nativeXComponentImpl);
/**
* @tc.steps: step3. register axis event for nativeXComponent instance
*/
auto callback = [](OH_NativeXComponent* /* nativeXComponent */, ArkUI_UIInputEvent* event,
ArkUI_UIInputEvent_Type type) { isAxis = true; };
nativeXComponent->RegisterUIAxisEventCallback(callback);
/**
* @tc.steps: step4. call HandleAxisEvent
*/
AxisInfo event;
pattern->HandleAxisEvent(event);
EXPECT_TRUE(isAxis);
}
/**
* @tc.name: XComponentOnAreaChangedInnerTest019
* @tc.desc: Test XComponent OnAreaChangedInner.
@ -871,7 +1000,6 @@ HWTEST_F(XComponentTestNg, XComponentDetachCallbackTest024, TestSize.Level1)
xComponentEventHub->FireDetachEvent(XCOMPONENT_ID);
EXPECT_FALSE(onDetachKey == CHECK_KEY);
onDetachKey.clear();
XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_COMPONENT_TYPE_VALUE);
xComponent.SetDetachCallback(std::move(onDetach));
@ -1046,7 +1174,6 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceTest, TestSize.Level1)
ASSERT_TRUE(nativeXComponentImpl);
pattern->hasXComponentInit_ = true;
/**
* @tc.steps: step3. call surfaceHide and surfaceShow event without register callbacks
* @tc.expected: no error happens and g_surfaceShowNum remains the same
@ -1095,135 +1222,6 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceTest, TestSize.Level1)
}
}
/**
* @tc.name: XComponentControllerTest
* @tc.desc: Test XComponentController's interface
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentControllerTest, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE_VALUE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
EXPECT_TRUE(frameNode);
EXPECT_EQ(frameNode->GetTag(), V2::XCOMPONENT_ETS_TAG);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
pattern->hasXComponentInit_ = true;
EXPECT_EQ(pattern->type_, XCOMPONENT_SURFACE_TYPE_VALUE);
EXPECT_TRUE(pattern->IsAtomicNode());
auto renderContext = AceType::MakeRefPtr<MockRenderContext>();
pattern->handlingSurfaceRenderContext_ = renderContext;
/**
* @tc.steps: step2. call XcomponentController's interface releative to SetSurfaceRect
* @tc.expected: handlingSurfaceRenderContext_->SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY,
* SURFACE_WIDTH, SURFACE_HEIGHT) is called
*/
auto xcomponentController = pattern->xcomponentController_;
EXPECT_TRUE(xcomponentController);
pattern->drawSize_ = MAX_SIZE;
xcomponentController->SetIdealSurfaceWidth(SURFACE_WIDTH);
xcomponentController->SetIdealSurfaceHeight(SURFACE_HEIGHT);
xcomponentController->SetIdealSurfaceOffsetX(SURFACE_OFFSETX);
xcomponentController->SetIdealSurfaceOffsetY(SURFACE_OFFSETY);
EXPECT_CALL(*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_),
SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, SURFACE_WIDTH, SURFACE_HEIGHT))
.WillOnce(Return());
xcomponentController->UpdateSurfaceBounds();
/**
* @tc.steps: step3. call XcomponentController's interface releative to GetSurfaceRect
* @tc.expected: the rect get from GetSurfaceRect equals the rect set by SetSurfaceRect
*/
auto surfaceWidth = 0.0f;
auto surfaceHeight = 0.0f;
auto surfaceOffsetX = 0.0f;
auto surfaceOffsetY = 0.0f;
xcomponentController->GetSurfaceSize(surfaceWidth, surfaceHeight);
xcomponentController->GetLocalLocation(surfaceOffsetX, surfaceOffsetY);
EXPECT_EQ(surfaceOffsetX, SURFACE_OFFSETX);
EXPECT_EQ(surfaceOffsetY, SURFACE_OFFSETY);
EXPECT_EQ(surfaceWidth, SURFACE_WIDTH);
EXPECT_EQ(surfaceHeight, SURFACE_HEIGHT);
/**
* @tc.steps: step4. call XcomponentController's ClearIdealSurfaceOffset
* @tc.expected: handlingSurfaceRenderContext_->SetBounds(newSurfaceOffsetX, newSurfaceOffsetY,
* SURFACE_WIDTH, SURFACE_HEIGHT) is called
*/
auto newSurfaceOffsetX = (MAX_WIDTH - SURFACE_WIDTH) / 2.0f;
auto newSurfaceOffsetY = (MAX_HEIGHT - SURFACE_HEIGHT) / 2.0f;
xcomponentController->ClearIdealSurfaceOffset(true);
xcomponentController->ClearIdealSurfaceOffset(false);
EXPECT_CALL(*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_),
SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, SURFACE_WIDTH, SURFACE_HEIGHT))
.WillOnce(Return());
xcomponentController->UpdateSurfaceBounds();
/**
* @tc.steps: step5. call XcomponentController's interface relative to SetSurfaceRotation
* @tc.expected: handlingSurfaceRenderContext_->SetSurfaceRotation(isLock) is called
*/
EXPECT_CALL(
*AceType::DynamicCast<MockRenderContext>(pattern->handlingSurfaceRenderContext_), SetSurfaceRotation(isLock))
.WillOnce(Return());
xcomponentController->SetSurfaceRotation(isLock);
/**
* @tc.steps: step6. call XcomponentController's interface relative to GetSurfaceRotation
* @tc.expected: the lock status get from GetSurfaceRotation equals the lock status set by SetSurfaceRotation
*/
auto lock = xcomponentController->GetSurfaceRotation();
EXPECT_EQ(lock, isLock);
}
/**
* @tc.name: XComponentAxisEventTest012
* @tc.desc: Test AxisEvent
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentAxisEventTest012, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
ASSERT_TRUE(frameNode);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
/**
* @tc.steps: step2. create nativeXComponent instance
* @tc.expected: focusHub & nativeXComponent instance create successfully
*/
auto pair = pattern->GetNativeXComponent();
auto weakNativeXComponent = pair.second;
auto nativeXComponent = weakNativeXComponent.lock();
auto nativeXComponentImpl = pair.first;
ASSERT_TRUE(nativeXComponent);
ASSERT_TRUE(nativeXComponentImpl);
/**
* @tc.steps: step3. register axis event for nativeXComponent instance
*/
auto callback = [](OH_NativeXComponent* /* nativeXComponent */, ArkUI_UIInputEvent* event,
ArkUI_UIInputEvent_Type type) { isAxis = true; };
nativeXComponent->RegisterUIAxisEventCallback(callback);
/**
* @tc.steps: step4. call HandleAxisEvent
*/
AxisInfo event;
pattern->HandleAxisEvent(event);
EXPECT_TRUE(isAxis);
}
/**
* @tc.name: XComponentSourceTypeTest
* @tc.desc: Test SourceType
@ -1261,40 +1259,6 @@ HWTEST_F(XComponentTestNg, XComponentSourceTypeTest, TestSize.Level1)
}
}
/**
* @tc.name: XComponentImageAnalyzerTest
* @tc.desc: Test Enable Image Analyzer
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentImageAnalyzerTest, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
ASSERT_TRUE(frameNode);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
/**
* @tc.steps: step2. call EnableImageAnalyzer
* @tc.expected: IsSupportImageAnalyzerFeature() return right value
*/
pattern->EnableAnalyzer(true);
EXPECT_TRUE(pattern->isEnableAnalyzer_);
if (ImageAnalyzerMgr::GetInstance().IsImageAnalyzerSupported()) {
EXPECT_TRUE(pattern->IsSupportImageAnalyzerFeature());
} else {
EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature());
}
pattern->imageAnalyzerManager_ = nullptr;
EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature());
}
/**
* @tc.name: XComponentSurfaceLifeCycleCallback
* @tc.desc: Test XComponentController's surface life cycle callback
@ -1362,4 +1326,39 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceLifeCycleCallback, TestSize.Level1)
pattern->OnDetachFromFrameNode(AceType::RawPtr(frameNode));
EXPECT_STREQ(SURFACE_ID.c_str(), onSurfaceDestroyedSurfaceId.c_str());
}
/**
* @tc.name: XComponentImageAnalyzerTest
* @tc.desc: Test Enable Image Analyzer
* @tc.type: FUNC
*/
HWTEST_F(XComponentTestNg, XComponentImageAnalyzerTest, TestSize.Level1)
{
/**
* @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode
* @tc.expected: xcomponent frameNode create successfully
*/
testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE;
auto frameNode = CreateXComponentNode(testProperty);
ASSERT_TRUE(frameNode);
auto pattern = frameNode->GetPattern<XComponentPattern>();
ASSERT_TRUE(pattern);
pattern->surfaceId_ = SURFACE_ID;
/**
* @tc.steps: step2. call EnableImageAnalyzer
* @tc.expected: IsSupportImageAnalyzerFeature() return right value
*/
pattern->EnableAnalyzer(true);
EXPECT_TRUE(pattern->isEnableAnalyzer_);
if (ImageAnalyzerMgr::GetInstance().IsImageAnalyzerSupported()) {
EXPECT_TRUE(pattern->IsSupportImageAnalyzerFeature());
} else {
EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature());
}
pattern->imageAnalyzerManager_ = nullptr;
EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature());
}
} // namespace OHOS::Ace::NG