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