• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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
16import { paramMock } from "../utils"
17import { PixelMapMock } from "./ohos_multimedia_image.js"
18
19export function mockPasteBoard() {
20  const PasteDataMock = {
21    getPrimaryText: function () {
22      console.warn("PasteData.getPrimaryText interface mocked in the Previewer. How this interface works on the" +
23        " Previewer may be different from that on a real device.")
24        return paramMock.paramStringMock
25    },
26    addHtmlRecord: function (...args) {
27      console.warn("PasteData.addHtmlRecord interface mocked in the Previewer. How this interface works on the" +
28        " Previewer may be different from that on a real device.")
29    },
30    addWantRecord: function (...args) {
31      console.warn("PasteData.addWantRecord interface mocked in the Previewer. How this interface works on the" +
32        " Previewer may be different from that on a real device.")
33    },
34    addRecord: function (...args) {
35      console.warn("PasteData.addRecord interface mocked in the Previewer. How this interface works on the" +
36        " Previewer may be different from that on a real device.")
37    },
38    addTextRecord: function (...args) {
39      console.warn("PasteData.addTextRecord interface mocked in the Previewer. How this interface works on the" +
40        " Previewer may be different from that on a real device.")
41    },
42    addUriRecord: function (...args) {
43      console.warn("PasteData.addUriRecord interface mocked in the Previewer. How this interface works on the" +
44        " Previewer may be different from that on a real device.")
45    },
46    addPixelMapRecord: function (...args) {
47      console.warn("PasteData.addPixelMapRecord interface mocked in the Previewer. How this interface works on the" +
48        " Previewer may be different from that on a real device.")
49    },
50    getMimeTypes: function () {
51      console.warn("PasteData.getMimeTypes interface mocked in the Previewer. How this interface works on the" +
52        " Previewer may be different from that on a real device.");
53      return new Array(paramMock.paramStringMock);
54    },
55    getPrimaryHtml: function () {
56      console.warn("PasteData.getPrimaryHtml interface mocked in the Previewer. How this interface works on the" +
57        " Previewer may be different from that on a real device.")
58      return paramMock.paramStringMock
59    },
60    getPrimaryWant: function () {
61      console.warn("PasteData.getPrimaryWant interface mocked in the Previewer. How this interface works on the" +
62        " Previewer may be different from that on a real device.")
63      return "[PC Preview] unknow getPrimaryWant"
64    },
65    getPrimaryMimeType: function () {
66      console.warn("PasteData.getPrimaryMimeType interface mocked in the Previewer. How this interface works on the" +
67        " Previewer may be different from that on a real device.")
68      return paramMock.paramStringMock
69    },
70    getPrimaryUri: function () {
71      console.warn("PasteData.getPrimaryUri interface mocked in the Previewer. How this interface works on the" +
72        " Previewer may be different from that on a real device.")
73      return paramMock.paramStringMock
74    },
75    getPrimaryPixelMap: function () {
76      console.warn("PasteData.getPrimaryPixelMap interface mocked in the Previewer. How this interface works on the" +
77        " Previewer may be different from that on a real device.")
78      return PixelMapMock
79    },
80    getProperty: function () {
81      console.warn("PasteData.getProperty interface mocked in the Previewer. How this interface works on the" +
82        " Previewer may be different from that on a real device.")
83      return PasteDataPropertyMock;
84    },
85    setProperty: function () {
86      console.warn("PasteData.setProperty interface mocked in the Previewer. How this interface works on the" +
87        " Previewer may be different from that on a real device.")
88    },
89    getRecordAt: function (...args) {
90      console.warn("PasteData.getRecordAt interface mocked in the Previewer. How this interface works on the" +
91        " Previewer may be different from that on a real device.")
92      return PasteDataRecordMock;
93    },
94    getRecordCount: function () {
95      console.warn("PasteData.getRecordCount interface mocked in the Previewer. How this interface works on the" +
96        " Previewer may be different from that on a real device.")
97      return paramMock.paramNumberMock
98    },
99    getTag: function () {
100      console.warn("PasteData.getTag interface mocked in the Previewer. How this interface works on the" +
101        " Previewer may be different from that on a real device.")
102      return paramMock.paramStringMock
103    },
104    hasMimeType: function (...args) {
105      console.warn("PasteData.hasMimeType interface mocked in the Previewer. How this interface works on the" +
106        " Previewer may be different from that on a real device.")
107      return paramMock.paramBooleanMock
108    },
109    removeRecordAt: function (...args) {
110      console.warn("PasteData.removeRecordAt interface mocked in the Previewer. How this interface works on the" +
111        " Previewer may be different from that on a real device.")
112      return paramMock.paramBooleanMock
113    },
114    replaceRecordAt: function (...args) {
115      console.warn("PasteData.replaceRecordAt interface mocked in the Previewer. How this interface works on the" +
116        " Previewer may be different from that on a real device.")
117      return paramMock.paramBooleanMock
118    }
119  }
120  const PasteDataRecordMock = {
121    htmlText: '[PC preview] unknow htmlText',
122    want: '[PC preview] unknow want',
123    mimeType: '[PC preview] unknow mimeType',
124    plainText: '[PC preview] unknow plainText',
125    uri: '[PC preview] unknow uri',
126    pixelMap: PixelMapMock,
127    data: {'mock_xml': new ArrayBuffer()},
128    convertToText: function (...args) {
129      console.warn("PasteDataRecord.convertToText interface mocked in the Previewer. How this interface works on the" +
130        " Previewer may be different from that on a real device.")
131      const len = args.length
132      if (typeof args[len - 1] === 'function') {
133        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
134      } else {
135        return new Promise((resolve, reject) => {
136          resolve(paramMock.paramStringMock);
137        })
138      }
139    }
140  }
141  const pasteboard = {
142    ShareOption: {
143      InApp: "[PC Preview] unknown InApp",
144      LocalDevice: "[PC Preview] unknown LocalDevice",
145      CrossDevice: "[PC Preview] unknown CrossDevice"
146    },
147    MAX_RECORD_NUM: '[PC preview] unknow MAX_RECORD_NUM',
148    MIMETYPE_TEXT_HTML: '[PC preview] unknow MIMETYPE_TEXT_HTML11111',
149    MIMETYPE_TEXT_WANT: '[PC preview] unknow MIMETYPE_TEXT_WANT',
150    MIMETYPE_TEXT_PLAIN: '[PC preview] unknow MIMETYPE_TEXT_PLAIN',
151    MIMETYPE_TEXT_URI: '[PC preview] unknow MIMETYPE_TEXT_URI',
152    MIMETYPE_PIXELMAP: '[PC preview] unknow MIMETYPE_PIXELMAP',
153    createPlainTextData: function (...args) {
154      console.warn("pasteboard.createPlainTextData interface mocked in the Previewer. How this interface works on" +
155        " the Previewer may be different from that on a real device.")
156      return PasteDataMock;
157    },
158    createHtmlData: function (...args) {
159      console.warn("pasteboard.createHtmlData interface mocked in the Previewer. How this interface works on" +
160        " the Previewer may be different from that on a real device.")
161      return PasteDataMock;
162    },
163    createUriData: function (...args) {
164      console.warn("pasteboard.createUriData interface mocked in the Previewer. How this interface works on" +
165        " the Previewer may be different from that on a real device.")
166      return PasteDataMock;
167    },
168    createPixelMapData: function (...args) {
169      console.warn("pasteboard.createPixelMapData interface mocked in the Previewer. How this interface works on" +
170        " the Previewer may be different from that on a real device.")
171      return PasteDataMock;
172    },
173    createData: function (...args) {
174      console.warn("pasteboard.createData interface mocked in the Previewer. How this interface works on" +
175        " the Previewer may be different from that on a real device.")
176      return PasteDataMock;
177    },
178    createWantData: function (...args) {
179      console.warn("pasteboard.createWantData interface mocked in the Previewer. How this interface works on" +
180        " the Previewer may be different from that on a real device.")
181      return PasteDataMock;
182    },
183    createHtmlTextRecord: function (...args) {
184      console.warn("pasteboard.createHtmlTextRecord interface mocked in the Previewer. How this interface works on" +
185        " the Previewer may be different from that on a real device.")
186      return PasteDataRecordMock;
187    },
188    createWantRecord: function (...args) {
189      console.warn("pasteboard.createWantRecord interface mocked in the Previewer. How this interface works on" +
190        " the Previewer may be different from that on a real device.")
191      return PasteDataRecordMock;
192    },
193    createUriRecord: function (...args) {
194      console.warn("pasteboard.createUriRecord interface mocked in the Previewer. How this interface works on" +
195        " the Previewer may be different from that on a real device.")
196      return PasteDataRecordMock;
197    },
198    createPixelMapRecord: function (...args) {
199      console.warn("pasteboard.createPixelMapRecord interface mocked in the Previewer. How this interface works on" +
200        " the Previewer may be different from that on a real device.")
201      return PasteDataRecordMock;
202    },
203    createRecord: function (...args) {
204      console.warn("pasteboard.createRecord interface mocked in the Previewer. How this interface works on" +
205        " the Previewer may be different from that on a real device.")
206      return PasteDataRecordMock;
207    },
208    createPlainTextRecord: function (...args) {
209      console.warn("pasteboard.createPlainTextRecord interface mocked in the Previewer. How this interface works on" +
210        " the Previewer may be different from that on a real device.")
211      return PasteDataRecordMock;
212    },
213    getSystemPasteboard: function () {
214      console.warn("pasteboard.getSystemPasteboard interface mocked in the Previewer. How this interface works on" +
215        " the Previewer may be different from that on a real device.")
216      return SystemPasteboardMock;
217    }
218  }
219  const PasteDataPropertyMock = {
220    additions: '[PC preview] unknow additions',
221    mimeTypes: new Array('[PC preview] unknow MIMETYPE_TEXT_PLAIN'),
222    tag: '[PC preview] unknow tag',
223    timestamp: '[PC preview] unknow timestamp',
224    localOnly: '[PC preview] unknow localOnly',
225    shareOption: pasteboard.ShareOption
226  }
227  const SystemPasteboardMock = {
228    on: function (...args) {
229      console.warn("SystemPasteboard.on interface mocked in the Previewer. How this interface works on the" +
230        " Previewer may be different from that on a real device.");
231      const len = args.length
232      if (typeof args[len - 1] === 'function') {
233        if (args[0] == 'update') {
234          args[len - 1].call(this);
235        }
236      }
237    },
238    off: function (...args) {
239      console.warn("SystemPasteboard.off interface mocked in the Previewer. How this interface works on the" +
240        " Previewer may be different from that on a real device.");
241      const len = args.length
242      if (typeof args[len - 1] === 'function') {
243        if (args[0] == 'update') {
244          args[len - 1].call(this);
245        }
246      }
247    },
248    clear: function (...args) {
249      console.warn("SystemPasteboard.clear interface mocked in the Previewer. How this interface works on the" +
250        " Previewer may be different from that on a real device.")
251      const len = args.length
252      if (typeof args[len - 1] === 'function') {
253        args[len - 1].call(this, paramMock.businessErrorMock)
254      } else {
255        return new Promise((resolve, reject) => {
256          resolve();
257        })
258      }
259    },
260    hasPasteData: function (...args) {
261      console.warn("SystemPasteboard.hasPasteData interface mocked in the Previewer. How this interface works on the" +
262        " Previewer may be different from that on a real device.")
263      const len = args.length
264      if (typeof args[len - 1] === 'function') {
265        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
266      } else {
267        return new Promise((resolve, reject) => {
268          resolve(paramMock.paramBooleanMock);
269        })
270      }
271    },
272    getPasteData: function (...args) {
273      console.warn("SystemPasteboard.getPasteData interface mocked in the Previewer. How this interface works on the" +
274        " Previewer may be different from that on a real device.")
275      const len = args.length
276      if (typeof args[len - 1] === 'function') {
277        args[len - 1].call(this, paramMock.businessErrorMock, PasteDataMock)
278      } else {
279        return new Promise((resolve, reject) => {
280          resolve(PasteDataMock);
281        })
282      }
283    },
284    setPasteData: function (...args) {
285      console.warn("SystemPasteboard.setPasteData interface mocked in the Previewer. How this interface works on the" +
286        " Previewer may be different from that on a real device.")
287      const len = args.length
288      if (typeof args[len - 1] === 'function') {
289        args[len - 1].call(this, paramMock.businessErrorMock);
290      } else {
291        return new Promise((resolve, reject) => {
292          resolve();
293        })
294      }
295    }
296  }
297  return pasteboard
298}
299