!43602 【UT】web_pattern覆盖率补充1

Merge pull request !43602 from wangweiyuan/web_pattern_test_supplement
This commit is contained in:
openharmony_ci 2024-09-23 12:43:34 +00:00 committed by Gitee
commit b9d8b36377
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 1995 additions and 1 deletions

View File

@ -18,6 +18,7 @@
#include "base/memory/ace_type.h"
#include "base/memory/referenced.h"
#include "base/utils/utils.h"
#include "core/accessibility/accessibility_manager.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/base/view_advanced_register.h"
#include "core/components_ng/pattern/root/root_pattern.h"
@ -26,6 +27,117 @@
#include "core/pipeline_ng/pipeline_context.h"
#include "core/pipeline_ng/ui_task_scheduler.h"
namespace OHOS::Ace {
constexpr int32_t COUNTER_NUMBER_ZERO = 0;
constexpr int32_t COUNTER_NUMBER_MAX = 9;
constexpr int32_t MOCK_REGISTER_DIVISOR = 2;
static int32_t registerStatus = 0;
class MockAccessibilityManager : public AccessibilityManager {
public:
MOCK_METHOD(void, SendAccessibilityAsyncEvent, (const AccessibilityEvent& accessibilityEvent), (override));
MOCK_METHOD(void, SendWebAccessibilityAsyncEvent,
(const AccessibilityEvent& accessibilityEvent, const RefPtr<NG::WebPattern>& webPattern), (override));
MOCK_METHOD(void, UpdateVirtualNodeFocus, (), (override));
MOCK_METHOD(int64_t, GenerateNextAccessibilityId, (), (override));
MOCK_METHOD(RefPtr<AccessibilityNode>, CreateSpecializedNode,
(const std::string& tag, int32_t nodeId, int32_t parentNodeId), (override));
MOCK_METHOD(RefPtr<AccessibilityNode>, CreateAccessibilityNode,
(const std::string& tag, int32_t nodeId, int32_t parentNodeId, int32_t itemIndex), (override));
MOCK_METHOD(RefPtr<AccessibilityNode>, GetAccessibilityNodeById, (NodeId nodeId), (const, override));
MOCK_METHOD(std::string, GetInspectorNodeById, (NodeId nodeId), (const, override));
MOCK_METHOD(void, RemoveAccessibilityNodes, (RefPtr<AccessibilityNode> & node), (override));
MOCK_METHOD(void, RemoveAccessibilityNodeById, (NodeId nodeId), (override));
MOCK_METHOD(void, ClearPageAccessibilityNodes, (int32_t pageId), (override));
MOCK_METHOD(void, SetRootNodeId, (int32_t nodeId), (override));
MOCK_METHOD(void, TrySaveTargetAndIdNode,
(const std::string& id, const std::string& target, const RefPtr<AccessibilityNode>& node), (override));
MOCK_METHOD(void, HandleComponentPostBinding, (), (override));
MOCK_METHOD(void, OnDumpInfo, (const std::vector<std::string>& params), (override));
MOCK_METHOD(
void, OnDumpInfoNG, (const std::vector<std::string>& params, uint32_t windowId, bool hasJson), (override));
MOCK_METHOD(void, SetCardViewPosition, (int id, float offsetX, float offsetY), (override));
MOCK_METHOD(void, SetCardViewParams, (const std::string& key, bool focus), (override));
MOCK_METHOD(void, SetSupportAction, (uint32_t action, bool isEnable), (override));
MOCK_METHOD(void, ClearNodeRectInfo, (RefPtr<AccessibilityNode> & node, bool isPopDialog), (override));
MOCK_METHOD(void, AddComposedElement, (const std::string& key, const RefPtr<ComposedElement>& node), (override));
MOCK_METHOD(void, RemoveComposedElementById, (const std::string& key), (override));
MOCK_METHOD(WeakPtr<ComposedElement>, GetComposedElementFromPage, (NodeId nodeId), (override));
MOCK_METHOD(void, TriggerVisibleChangeEvent, (), (override));
MOCK_METHOD(void, AddVisibleChangeNode, (NodeId nodeId, double ratio, VisibleRatioCallback callback), (override));
MOCK_METHOD(void, RemoveVisibleChangeNode, (NodeId nodeId), (override));
MOCK_METHOD(bool, IsVisibleChangeNodeExists, (NodeId nodeId), (override));
MOCK_METHOD(void, UpdateEventTarget, (NodeId id, BaseEventInfo& info), (override));
MOCK_METHOD(void, SetWindowPos, (int32_t left, int32_t top, int32_t windowId), (override));
#ifdef WINDOW_SCENE_SUPPORTED
MOCK_METHOD(void, SearchElementInfoByAccessibilityIdNG,
(int64_t elementId, int32_t mode, std::list<Accessibility::AccessibilityElementInfo>& infos,
const RefPtr<PipelineBase>& context, int64_t uiExtensionOffset),
(override));
MOCK_METHOD(void, SearchElementInfosByTextNG,
(int64_t elementId, const std::string& text, std::list<Accessibility::AccessibilityElementInfo>& infos,
const RefPtr<PipelineBase>& context, const int64_t uiExtensionOffset),
(override));
MOCK_METHOD(void, FindFocusedElementInfoNG,
(int64_t elementId, int32_t focusType, Accessibility::AccessibilityElementInfo& info,
const RefPtr<PipelineBase>& context, const int64_t uiExtensionOffset),
(override));
MOCK_METHOD(void, FocusMoveSearchNG,
(int64_t elementId, int32_t direction, Accessibility::AccessibilityElementInfo& info,
const RefPtr<PipelineBase>& context, const int64_t uiExtensionOffset),
(override));
MOCK_METHOD(bool, ExecuteExtensionActionNG,
(int64_t elementId, const std::map<std::string, std::string>& actionArguments, int32_t action,
const RefPtr<PipelineBase>& context, int64_t uiExtensionOffset),
(override));
MOCK_METHOD(bool, TransferAccessibilityAsyncEvent,
(const Accessibility::AccessibilityEventInfo& eventInfo, int64_t uiExtensionOffset), (override));
MOCK_METHOD(void, SendExtensionAccessibilityEvent,
(const Accessibility::AccessibilityEventInfo& eventInfo, int64_t uiExtensionOffset), (override));
#endif
#ifdef WEB_SUPPORTED
MOCK_METHOD(bool, RegisterWebInteractionOperationAsChildTree,
(int64_t accessibilityId, const WeakPtr<NG::WebPattern>& webPattern), (override));
MOCK_METHOD(bool, DeregisterWebInteractionOperationAsChildTree, (int32_t treeId), (override));
#endif
void RegisterAccessibilityChildTreeCallback(
int64_t elementId, const std::shared_ptr<AccessibilityChildTreeCallback>& callback) override
{}
void DeregisterAccessibilityChildTreeCallback(int64_t elementId) override {}
void RegisterInteractionOperationAsChildTree(
uint32_t parentWindowId, int32_t parentTreeId, int64_t parentElementId) override
{
if (registerStatus % MOCK_REGISTER_DIVISOR == COUNTER_NUMBER_ZERO) {
registerStatus++;
Register(true);
} else {
registerStatus++;
Register(false);
}
if (registerStatus > COUNTER_NUMBER_MAX)
registerStatus = COUNTER_NUMBER_ZERO;
}
void SetAccessibilityGetParentRectHandler(std::function<void(int32_t&, int32_t&)>&& callback) override {}
void SetAccessibilityGetParentRectHandler(std::function<void(AccessibilityParentRectInfo&)>&& callback) override {}
MOCK_METHOD(void, DeregisterInteractionOperationAsChildTree, (), (override));
MOCK_METHOD(void, SendEventToAccessibilityWithNode,
(const AccessibilityEvent& accessibilityEvent, const RefPtr<AceType>& node,
const RefPtr<PipelineBase>& context),
(override));
MOCK_METHOD(void, RegisterAccessibilitySAObserverCallback,
(int64_t elementId, const std::shared_ptr<AccessibilitySAObserverCallback>& callback), (override));
MOCK_METHOD(void, DeregisterAccessibilitySAObserverCallback, (int64_t elementId), (override));
MOCK_METHOD(bool, RegisterInteractionOperationAsChildTree, (const Registration& registration), (override));
MOCK_METHOD(bool, DeregisterInteractionOperationAsChildTree, (uint32_t windowId, int32_t treeId), (override));
MOCK_METHOD(void, TransferThirdProviderHoverEvent,
(const WeakPtr<NG::FrameNode>& hostNode, const NG::PointF& point, SourceType source,
NG::AccessibilityHoverEventType eventType, TimeStamp time),
(override));
MOCK_METHOD(bool, OnDumpChildInfoForThird,
(int64_t hostElementId, const std::vector<std::string>& params, std::vector<std::string>& info), (override));
};
} // namespace OHOS::Ace
namespace OHOS::Ace::NG {
namespace {
constexpr double DISPLAY_WIDTH = 720;
@ -853,7 +965,7 @@ void PipelineBase::PostSyncEvent(const TaskExecutor::Task& task, const std::stri
RefPtr<AccessibilityManager> PipelineBase::GetAccessibilityManager() const
{
return nullptr;
return AceType::MakeRefPtr<MockAccessibilityManager>();
}
#ifdef WINDOW_SCENE_SUPPORTED

View File

@ -638,6 +638,10 @@ ohos_unittest("web_pattern_unit_test_ohos") {
"web_pattern_window_test_ng.cpp",
]
sources += [ "web_pattern_test_ng_supplement.cpp" ]
sources -=
[ "$ace_root/frameworks/core/components_ng/pattern/web/web_pattern.cpp" ]
deps = [
"$ace_root/frameworks/core/components/custom_paint:ace_core_components_custom_paint_ohos",
"$ace_root/frameworks/core/components/theme:build_theme_code",

View File

@ -14,10 +14,206 @@
*/
#include <vector>
#include <gmock/gmock.h>
#include "core/components/web/resource/web_delegate.h"
namespace OHOS::Ace {
#define EGLCONFIG_VERSION 3
constexpr int32_t COUNTER_NUMBER_ZERO = 0;
constexpr int32_t NODE_INFO_DIVISOR = 2;
class MockNWebAccessibilityNodeInfoOnlyForReturn : public NWeb::NWebAccessibilityNodeInfo {
public:
std::string GetHint() override
{
return "";
}
std::string GetError() override
{
return "";
}
int32_t GetRectX()
{
return 0;
}
int32_t GetRectY()
{
return 0;
}
void SetPageId(int32_t pageId) override {}
int32_t GetPageId() override
{
return 0;
}
std::vector<uint32_t> GetActions() override
{
return {};
}
std::string GetContent() override
{
return "";
}
std::vector<int64_t> GetChildIds() override
{
return {};
}
void SetParentId(int64_t parentId) override {}
int64_t GetParentId() override
{
return 0;
}
bool GetIsHeading() override
{
return false;
}
bool GetIsChecked() override
{
return false;
}
bool GetIsEnabled() override
{
return false;
}
bool GetIsFocused() override
{
return false;
}
int32_t GetRectWidth()
{
return 0;
}
int32_t GetRectHeight()
{
return 0;
}
bool GetIsVisible() override
{
return false;
}
bool GetIsHinting() override
{
return false;
}
bool GetIsEditable() override
{
return false;
}
bool GetIsSelected() override
{
return false;
}
size_t GetItemCounts() override
{
return 0;
}
int32_t GetLiveRegion() override
{
return 0;
}
bool GetIsPassword() override
{
return false;
}
bool GetIsCheckable() override
{
return false;
}
bool GetIsClickable() override
{
return false;
}
bool GetIsFocusable() override
{
return false;
}
bool GetIsScrollable() override
{
return false;
}
bool GetIsDeletable() override
{
return false;
}
int64_t GetAccessibilityId() override
{
return 0;
}
bool GetIsPopupSupported() override
{
return false;
}
bool GetIsContentInvalid() override
{
return false;
}
int32_t GetSelectionEnd() override
{
return 0;
}
int32_t GetSelectionStart() override
{
return 0;
}
float GetRangeInfoMin() override
{
return 0.0f;
}
float GetRangeInfoMax() override
{
return 0.0f;
}
float GetRangeInfoCurrent() override
{
return 0.0f;
}
int32_t GetInputType() override
{
return 0;
}
std::string GetComponentType() override
{
return "";
}
std::string GetDescriptionInfo() override
{
return "";
}
int32_t GetGridRows() override
{
return 0;
}
int32_t GetGridItemRow() override
{
return 0;
}
int32_t GetGridColumns() override
{
return 0;
}
int32_t GetGridItemColumn() override
{
return 0;
}
int32_t GetGridItemRowSpan() override
{
return 0;
}
int32_t GetGridSelectedMode() override
{
return 0;
}
int32_t GetGridItemColumnSpan() override
{
return 0;
}
bool GetIsAccessibilityFocus() override
{
return false;
}
bool GetIsPluralLineSupported() override
{
return false;
}
};
void WebMessagePortOhos::SetPortHandle(std::string& handle)
{
}
@ -1350,6 +1546,9 @@ std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> WebDelegate::GetFocusedAc
std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> WebDelegate::GetAccessibilityNodeInfoById(
int64_t accessibilityId)
{
if (accessibilityId % NODE_INFO_DIVISOR == COUNTER_NUMBER_ZERO) {
return std::make_shared<MockNWebAccessibilityNodeInfoOnlyForReturn>();
}
return nullptr;
}
std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> WebDelegate::GetAccessibilityNodeInfoByFocusMove(

File diff suppressed because it is too large Load Diff