1/*
2 * Copyright (c) 2022 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 NWEB_CREAT_WINDOW_H
17#define NWEB_CREAT_WINDOW_H
18
19#include "nweb.h"
20#include "nweb_init_params.h"
21
22#define private public
23#include "ui/rs_surface_node.h"
24#undef private
25
26namespace OHOS::NWeb {
27std::shared_ptr<NWebEngineInitArgsImpl> GetInitArgs(void);
28std::shared_ptr<NWeb> GetNwebForTest();
29
30class NWebMock : public NWeb {
31public:
32    void Resize(uint32_t width, uint32_t height, bool isKeyboard = false) override
33    {}
34    void OnPause() override
35    {}
36    void OnContinue() override
37    {}
38    void OnDestroy() override
39    {}
40    void OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) override
41    {}
42    void OnBlur(const BlurReason& blurReason) override
43    {}
44    void OnTouchPress(int32_t id, double x, double y, bool fromOverlay = false) override
45    {}
46    void OnTouchRelease(int32_t id, double x = 0, double y = 0, bool fromOverlay = false) override
47    {}
48    void OnTouchMove(int32_t id, double x, double y, bool fromOverlay = false) override
49    {}
50    void OnTouchMove(const std::vector<std::shared_ptr<NWebTouchPointInfo>> &touch_point_infos,
51                     bool fromOverlay = false) override
52    {}
53    void OnTouchCancel() override
54    {}
55    void OnNavigateBack() override
56    {}
57    bool SendKeyEvent(int32_t keyCode, int32_t keyAction) override
58    {
59        return true;
60    }
61    void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) override
62    {}
63    void SendMouseEvent(int x, int y, int button, int action, int count) override
64    {}
65    int Load(const std::string& url) override
66    {
67        return 0;
68    }
69    bool IsNavigatebackwardAllowed() override
70    {
71        return true;
72    }
73    bool IsNavigateForwardAllowed() override
74    {
75        return true;
76    }
77    bool CanNavigateBackOrForward(int numSteps) override
78    {
79        return true;
80    }
81    void NavigateBack() override
82    {}
83    void NavigateForward() override
84    {}
85    void NavigateBackOrForward(int step) override
86    {}
87    void DeleteNavigateHistory() override
88    {}
89    void Reload() override
90    {}
91    int Zoom(float zoomFactor) override
92    {
93        return 0;
94    }
95    int ZoomIn() override
96    {
97        return 0;
98    }
99    int ZoomOut() override
100    {
101        return 0;
102    }
103    void Stop() override
104    {}
105    void ExecuteJavaScript(const std::string& code) override
106    {}
107    void ExecuteJavaScript(
108        const std::string& code,
109        std::shared_ptr<NWebMessageValueCallback> callback,
110        bool extention) override
111    {}
112    std::shared_ptr<NWebPreference> GetPreference() override
113    {
114        return nullptr;
115    }
116    unsigned int GetWebId() override
117    {
118        return 0;
119    }
120    std::shared_ptr<HitTestResult> GetHitTestResult() override
121    {
122        std::shared_ptr<HitTestResult> test;
123        return test;
124    }
125    void PutBackgroundColor(int color) override
126    {}
127    void InitialScale(float scale) override
128    {}
129    void PutDownloadCallback(
130        std::shared_ptr<NWebDownloadCallback> downloadListener) override
131    {}
132    void PutReleaseSurfaceCallback(
133        std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener) override
134    {}
135    void SetNWebHandler(std::shared_ptr<NWebHandler> handler) override
136    {}
137    std::string Title() override
138    {
139        return nullptr;
140    }
141    int PageLoadProgress() override
142    {
143        return 0;
144    }
145    int ContentHeight() override
146    {
147        return 0;
148    }
149    float Scale() override
150    {
151        return 0;
152    }
153    int Load(
154        const std::string& url,
155        const std::map<std::string, std::string> &additionalHttpHeaders) override
156    {
157        return 0;
158    }
159    int LoadWithDataAndBaseUrl(const std::string& baseUrl,
160                                        const std::string& data,
161                                        const std::string& mimeType,
162                                        const std::string& encoding,
163                                        const std::string& historyUrl) override
164    {
165        return 0;
166    }
167    int LoadWithData(const std::string& data,
168                              const std::string& mimeType,
169                              const std::string& encoding) override
170    {
171        return 0;
172    }
173    void RegisterArkJSfunction(
174        const std::string& object_name, const std::vector<std::string>& method_list, const int32_t object_id) override
175    {}
176    void UnregisterArkJSfunction(
177        const std::string& object_name,
178        const std::vector<std::string>& method_list) override
179    {}
180    void SetNWebJavaScriptResultCallBack(
181        std::shared_ptr<NWebJavaScriptResultCallBack> callback) override
182    {}
183    void PutFindCallback(
184        std::shared_ptr<NWebFindCallback> findListener) override
185    {}
186    void FindAllAsync(const std::string &searchStr) override
187    {}
188    void ClearMatches() override
189    {}
190    void FindNext(const bool forward) override
191    {}
192    void StoreWebArchive(const std::string &baseName, bool autoName,
193        std::shared_ptr<NWebStringValueCallback> callback) override
194    {}
195    std::vector<std::string> CreateWebMessagePorts() override
196    {
197        std::vector<std::string> empty;
198        return empty;
199    }
200    void PostWebMessage(const std::string& message, const std::vector<std::string>& ports, const std::string& targetUri)
201        override
202    {}
203    void ClosePort(const std::string& handle) override
204    {}
205    void PostPortMessage(const std::string& handle, std::shared_ptr<NWebMessage> data) override
206    {}
207    void SetPortMessageCallback(const std::string& handle,
208        std::shared_ptr<NWebMessageValueCallback> callback) override
209    {}
210    void SendDragEvent(std::shared_ptr<NWebDragEvent> dragEvent) override
211    {}
212    void ClearSslCache() override
213    {}
214    std::string GetUrl() override
215    {
216        return "/data";
217    }
218    void ClearClientAuthenticationCache() override
219    {}
220    void UpdateLocale(const std::string& language, const std::string& region) override
221    {}
222
223    const std::string GetOriginalUrl() override
224    {
225        return "";
226    }
227    bool GetFavicon(const void** data, size_t& width, size_t& height,
228        ImageColorType& colorType, ImageAlphaType& alphaType) override
229    {
230        return false;
231    }
232    void PutNetworkAvailable(bool available) override
233    {}
234
235    void HasImages(std::shared_ptr<NWebBoolValueCallback> callback) override
236    {}
237
238    void RemoveCache(bool include_disk_files) override
239    {}
240    std::shared_ptr<NWebHistoryList> GetHistoryList() override
241    {
242        return nullptr;
243    }
244    std::vector<uint8_t> SerializeWebState() override
245    {
246        std::vector<uint8_t> empty;
247        return empty;
248    }
249    bool RestoreWebState(const std::vector<uint8_t> &state) override
250    {
251        return false;
252    }
253    void PageUp(bool top) override
254    {}
255    void PageDown(bool bottom) override
256    {}
257    void ScrollTo(float x, float y) override
258    {}
259    void ScrollBy(float deltaX, float deltaY) override
260    {}
261    void SlideScroll(float vx, float vy) override
262    {}
263    bool GetCertChainDerData(std::vector<std::string>& certChainData, bool isSingleCert) override
264    {
265        return false;
266    }
267    void SetScreenOffSet(double x, double y) override
268    {}
269    void SetAudioMuted(bool muted) override
270    {}
271    void SetShouldFrameSubmissionBeforeDraw(bool should) override
272    {}
273    void NotifyPopupWindowResult(bool result) override
274    {}
275    void SetAudioResumeInterval(int32_t resumeInterval) override
276    {}
277    void SetAudioExclusive(bool audioExclusive) override
278    {}
279    void RegisterScreenLockFunction(int32_t windowId, std::shared_ptr<NWebScreenLockCallback> callback) override
280    {}
281    void UnRegisterScreenLockFunction(int32_t windowId) override
282    {}
283    std::shared_ptr<NWebDragData> GetOrCreateDragData() override
284    {
285        return nullptr;
286    }
287    void SendTouchpadFlingEvent(double x, double y, double vx, double vy) override
288    {}
289    int SetUrlTrustList(const std::string& urlTrustList) override
290    {
291        return 0;
292    }
293    int SetUrlTrustListWithErrMsg(const std::string& urlTrustList, std::string& detailErrMsg) override
294    {
295        return 0;
296    }
297};
298}
299#endif
300