1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_TEST_MOCK_MOCK_UICONTENT_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_TEST_MOCK_MOCK_UICONTENT_H
18 
19 #include "gmock/gmock.h"
20 
21 #include "accessibility_element_info.h"
22 #include "ui_content.h"
23 
24 namespace OHOS {
25 namespace Ace {
26 class MockUIContent : public UIContent {
27 public:
28     MockUIContent() = default;
29     ~MockUIContent() override = default;
30     MOCK_METHOD3(Initialize, UIContentErrorCode(OHOS::Rosen::Window *window, const std::string &url,
31         napi_value storage));
32     MOCK_METHOD3(Initialize, UIContentErrorCode(OHOS::Rosen::Window *window,
33         const std::shared_ptr<std::vector<uint8_t>> &content, napi_value storage));
34     MOCK_METHOD3(InitializeByName, UIContentErrorCode(OHOS::Rosen::Window *window,
35         const std::string &name, napi_value storage));
36     MOCK_METHOD4(Initialize,
37         void(OHOS::Rosen::Window *window, const std::string &url, napi_value storage, uint32_t focusWindowID));
38     MOCK_METHOD0(Foreground, void());
39     MOCK_METHOD0(Background, void());
40     MOCK_METHOD0(Focus, void());
41     MOCK_METHOD0(UnFocus, void());
42     MOCK_METHOD0(Destroy, void());
43     MOCK_METHOD1(OnNewWant, void(const OHOS::AAFwk::Want &want));
44     MOCK_METHOD4(Restore, UIContentErrorCode(OHOS::Rosen::Window *window, const std::string &contentInfo,
45         napi_value storage, ContentInfoType type));
46     MOCK_CONST_METHOD1(GetContentInfo, std::string(ContentInfoType type));
47     MOCK_METHOD0(DestroyUIDirector, void());
48     MOCK_METHOD0(ProcessBackPressed, bool());
49     MOCK_METHOD1(ProcessPointerEvent, bool(const std::shared_ptr<OHOS::MMI::PointerEvent> &pointerEvent));
50     MOCK_METHOD2(ProcessPointerEventWithCallback,
51         bool(const std::shared_ptr<OHOS::MMI::PointerEvent> &pointerEvent, const std::function<void()> &callback));
52     MOCK_METHOD2(ProcessKeyEvent, bool(const std::shared_ptr<OHOS::MMI::KeyEvent> &keyEvent, bool isPreIme));
53     MOCK_METHOD1(ProcessAxisEvent, bool(const std::shared_ptr<OHOS::MMI::AxisEvent> &axisEvent));
54     MOCK_METHOD1(ProcessVsyncEvent, bool(uint64_t timeStampNanos));
55     MOCK_METHOD1(UpdateConfiguration, void(const std::shared_ptr<OHOS::AppExecFwk::Configuration> &config));
56     MOCK_METHOD2(UpdateWindowMode, void(OHOS::Rosen::WindowMode mode, bool hasDeco));
57     MOCK_METHOD2(UpdateTitleInTargetPos, void(bool isShow, int32_t height));
58     MOCK_METHOD2(UpdateDecorVisible, void(bool visible, bool hasDeco));
59     MOCK_METHOD4(HideWindowTitleButton, void(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose));
60     MOCK_METHOD1(SetIgnoreViewSafeArea, void(bool ignoreViewSafeArea));
61     MOCK_METHOD0(GetBackgroundColor, uint32_t());
62     MOCK_METHOD1(SetBackgroundColor, void(uint32_t color));
63     MOCK_METHOD2(DumpInfo, void(const std::vector<std::string> &params, std::vector<std::string> &info));
64     MOCK_METHOD1(SetNextFrameLayoutCallback, void(std::function<void()> &&callback));
65     MOCK_METHOD1(NotifyMemoryLevel, void(int32_t level));
66     MOCK_METHOD1(SetAppWindowTitle, void(const std::string &title));
67     MOCK_METHOD1(SetAppWindowIcon, void(const std::shared_ptr<Media::PixelMap> &pixelMap));
68     MOCK_METHOD3(PreInitializeForm, void(OHOS::Rosen::Window *window, const std::string &url, napi_value storage));
69     MOCK_METHOD0(RunFormPage, void());
70     MOCK_METHOD0(GetFormRootNode, std::shared_ptr<Rosen::RSSurfaceNode>());
71     MOCK_METHOD1(UpdateFormData, void(const std::string &data));
72     MOCK_METHOD1(
73         UpdateFormSharedImage, void(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>> &imageDataMap));
74     MOCK_METHOD1(SetFormWidth, void(const float width));
75     MOCK_METHOD1(SetFormHeight, void(const float height));
76     MOCK_METHOD0(GetFormWidth, float());
77     MOCK_METHOD0(GetFormHeight, float());
78     MOCK_METHOD4(OnFormSurfaceChange, void(float width, float height, OHOS::Rosen::WindowSizeChangeReason reason,
79         const std::shared_ptr<OHOS::Rosen::RSTransaction> &rsTransaction));
80     MOCK_METHOD1(SetActionEventHandler, void(std::function<void(const std::string &action)> &&actionCallback));
81     MOCK_METHOD1(SetFormLinkInfoUpdateHandler, void(std::function<void(const std::vector<std::string>&)> &&callback));
82     MOCK_METHOD1(SetErrorEventHandler,
83         void(std::function<void(const std::string &code, const std::string &msg)> &&actionCallback));
84     MOCK_METHOD1(ReloadForm, void(const std::string &url));
85     MOCK_METHOD1(SetIsFocusActive, void(bool isFocusActive));
86 
87     MOCK_METHOD3(CreateModalUIExtension, int32_t(const AAFwk::Want &want,
88         const ModalUIExtensionCallbacks &callbacks, const ModalUIExtensionConfig &config));
89     MOCK_METHOD1(CloseModalUIExtension, void(int32_t sessionId));
90     MOCK_METHOD1(SetParentToken, void(sptr<IRemoteObject> token));
91     MOCK_METHOD0(GetParentToken, sptr<IRemoteObject>());
92 
93     MOCK_METHOD2(SetContainerModalTitleVisible, void(bool customTitleSettedShow, bool floatingTitleSettedShow));
94     MOCK_METHOD1(SetContainerModalTitleHeight, void(int height));
95     MOCK_METHOD0(GetContainerModalTitleHeight, int());
96     MOCK_METHOD2(GetContainerModalButtonsRect, bool(Rosen::Rect &containerModal, Rosen::Rect &buttons));
97     MOCK_METHOD1(SubscribeContainerModalButtonsRectChange, void(
98         std::function<void(Rosen::Rect &containerModal, Rosen::Rect &buttons)> &&callback));
99     MOCK_METHOD0(GetFormSerializedGesture, SerializedGesture());
100     MOCK_METHOD2(SetForceSplitEnable, void(bool isForceSplit, const std::string& homePage));
101 
102 #ifndef PREVIEW
103     MOCK_METHOD4(
104         SearchElementInfoByAccessibilityId, void(int64_t elementId,
105         int32_t mode, int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo> &output));
106     MOCK_METHOD4(
107         SearchElementInfosByText, void(int64_t elementId,
108         const std::string &text, int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo> &output));
109     MOCK_METHOD4(
110         FindFocusedElementInfo, void(int64_t elementId,
111         int32_t focusType, int64_t baseParent, Accessibility::AccessibilityElementInfo &output));
112     MOCK_METHOD4(
113         FocusMoveSearch, void(int64_t elementId, int32_t direction,
114         int64_t baseParent, Accessibility::AccessibilityElementInfo &output));
115 #endif
116     MOCK_METHOD1(GetAppPaintSize, void(OHOS::Rosen::Rect&));
117     MOCK_METHOD3(CreateCustomPopupUIExtension, int32_t(const AAFwk::Want &want,
118         const ModalUIExtensionCallbacks &callbacks, const CustomPopupUIExtensionConfig &config));
119     MOCK_METHOD1(DestroyCustomPopupUIExtension, void(int32_t nodeId));
120     MOCK_METHOD1(UpdateTransform, void(const OHOS::Rosen::Transform &transform));
121     MOCK_METHOD2(UpdateSizeOfPopupUIExtension, void(int32_t nodeId, std::optional<PopupSize> &targetSize));
122 };
123 
Create(OHOS::AbilityRuntime::Context *,NativeEngine *)124 std::unique_ptr<Ace::UIContent> UIContent::Create(OHOS::AbilityRuntime::Context *, NativeEngine *)
125 {
126     return std::make_unique<Ace::MockUIContent>();
127 }
128 } // namespace Ace
129 } // namespace OHOS
130 
131 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_TEST_MOCK_MOCK_UICONTENT_H
132