1/* 2 * Copyright (c) 2021 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 mockInputMethodEngine() { 19 const EditingText = { 20 textContent: "[PC Preview] unknow textContent", 21 offset: 1, 22 changedStart: 2, 23 changedEnd: 3, 24 selectionStart: 4, 25 selectionEnd: 5, 26 additionalBitFlags: 6, 27 prompt: "[PC Preview] unknow prompt" 28 } 29 const EditingCapability = { 30 maxLines: 1, 31 maxChars: 2 32 } 33 const EditorAttribute = { 34 inputPattern: 1, 35 enterKeyType: 2, 36 inputOption: 3 37 } 38 const KeyEvent = { 39 keyCode: "[PC Preview] unknow keyCode", 40 keyAction: "[PC Preview] unknow keyAction" 41 } 42 const RichContent = { 43 contentURI: "[PC Preview] unknow contentURI", 44 linkURI: "[PC Preview] unknow linkURI", 45 mimeTypes: "[PC Preview] unknow mimeTypes", 46 detail: "[PC Preview] unknow detail" 47 } 48 const KeyboardControllerMock = { 49 setDisplayMode: function (...args) { 50 console.warn("KeyboardController.setDisplayMode interface mocked in the Previewer. How this interface works on" + 51 " the Previewer may be different from that on a real device.") 52 const len = args.length 53 if (typeof args[len - 1] === 'function') { 54 args[len - 1].call(this, paramMock.businessErrorMock); 55 } else { 56 return new Promise((resolve, reject) => { 57 resolve(); 58 }) 59 } 60 }, 61 getDisplayMode: function (...args) { 62 console.warn("KeyboardController.getDisplayMode interface mocked in the Previewer. How this interface works on" + 63 " the Previewer may be different from that on a real device.") 64 const len = args.length 65 if (typeof args[len - 1] === 'function') { 66 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 67 } else { 68 return new Promise((resolve, reject) => { 69 resolve(paramMock.paramNumberMock); 70 }) 71 } 72 }, 73 hideKeyboard: function (...args) { 74 console.warn("KeyboardController.hideKeyboard interface mocked in the Previewer. How this interface works on" + 75 " the Previewer may be different from that on a real device.") 76 const len = args.length 77 if (typeof args[len - 1] === 'function') { 78 args[len - 1].call(this, paramMock.businessErrorMock); 79 } else { 80 return new Promise((resolve, reject) => { 81 resolve(); 82 }) 83 } 84 }, 85 toNextInputMethod: function (...args) { 86 console.warn("KeyboardController.toNextInputMethod interface mocked in the Previewer. How this interface works on" + 87 " the Previewer may be different from that on a real device.") 88 const len = args.length 89 if (typeof args[len - 1] === 'function') { 90 args[len - 1].call(this, paramMock.businessErrorMock); 91 } else { 92 return new Promise((resolve, reject) => { 93 resolve(); 94 }) 95 } 96 }, 97 getScreenOrientation: function (...args) { 98 console.warn("KeyboardController.getScreenOrientation interface mocked in the Previewer. How this interface works on" + 99 " the Previewer may be different from that on a real device.") 100 const len = args.length 101 if (typeof args[len - 1] === 'function') { 102 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve(paramMock.paramNumberMock); 106 }) 107 } 108 } 109 } 110 const TextInputClientMock = { 111 getEditorAttribute: function (...args) { 112 console.warn("TextInputClientMock.getEditorAttribute interface mocked in the Previewer. How this interface works on" + 113 " the Previewer may be different from that on a real device.") 114 const len = args.length 115 if (typeof args[len - 1] === 'function') { 116 args[len - 1].call(this, paramMock.businessErrorMock, EditorAttribute); 117 } else { 118 return new Promise((resolve, reject) => { 119 resolve(EditorAttribute); 120 }) 121 } 122 }, 123 insertText: function (...args) { 124 console.warn("TextInputClientMock.insertText interface mocked in the Previewer. How this interface works on" + 125 " the Previewer may be different from that on a real device.") 126 const len = args.length 127 if (typeof args[len - 1] === 'function') { 128 args[len - 1].call(this, paramMock.businessErrorMock); 129 } else { 130 return new Promise((resolve, reject) => { 131 resolve(); 132 }) 133 } 134 }, 135 insertRichContent: function (...args) { 136 console.warn("TextInputClientMock.insertRichContent interface mocked in the Previewer. How this interface works on" + 137 " the Previewer may be different from that on a real device.") 138 const len = args.length 139 if (typeof args[len - 1] === 'function') { 140 args[len - 1].call(this, paramMock.businessErrorMock); 141 } else { 142 return new Promise((resolve, reject) => { 143 resolve(); 144 }) 145 } 146 }, 147 deleteBackward: function (...args) { 148 console.warn("TextInputClientMock.deleteBackward interface mocked in the Previewer. How this interface works on" + 149 " the Previewer may be different from that on a real device.") 150 const len = args.length 151 if (typeof args[len - 1] === 'function') { 152 args[len - 1].call(this, paramMock.businessErrorMock); 153 } else { 154 return new Promise((resolve, reject) => { 155 resolve(); 156 }) 157 } 158 }, 159 deleteForward: function (...args) { 160 console.warn("TextInputClientMock.deleteForward interface mocked in the Previewer. How this interface works on" + 161 " the Previewer may be different from that on a real device.") 162 const len = args.length 163 if (typeof args[len - 1] === 'function') { 164 args[len - 1].call(this, paramMock.businessErrorMock); 165 } else { 166 return new Promise((resolve, reject) => { 167 resolve(); 168 }) 169 } 170 }, 171 getForward: function (...args) { 172 console.warn("TextInputClientMock.getForward interface mocked in the Previewer. How this interface works on" + 173 " the Previewer may be different from that on a real device.") 174 const len = args.length 175 if (typeof args[len - 1] === 'function') { 176 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 177 } else { 178 return new Promise((resolve, reject) => { 179 resolve(paramMock.paramStringMock); 180 }) 181 } 182 }, 183 getBackward: function (...args) { 184 console.warn("TextInputClientMock.getBackward interface mocked in the Previewer. How this interface works on" + 185 " the Previewer may be different from that on a real device.") 186 const len = args.length 187 if (typeof args[len - 1] === 'function') { 188 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 189 } else { 190 return new Promise((resolve, reject) => { 191 resolve(paramMock.paramStringMock); 192 }) 193 } 194 }, 195 getEditingText: function (...args) { 196 console.warn("TextInputClientMock.getEditingText interface mocked in the Previewer. How this interface works on" + 197 " the Previewer may be different from that on a real device.") 198 const len = args.length 199 if (typeof args[len - 1] === 'function') { 200 args[len - 1].call(this, paramMock.businessErrorMock, EditingText); 201 } else { 202 return new Promise((resolve, reject) => { 203 resolve(EditingText); 204 }) 205 } 206 }, 207 sendKeyEvent: function (...args) { 208 console.warn("TextInputClientMock.sendKeyEvent interface mocked in the Previewer. How this interface works on" + 209 " the Previewer may be different from that on a real device.") 210 const len = args.length 211 if (typeof args[len - 1] === 'function') { 212 args[len - 1].call(this, paramMock.businessErrorMock); 213 } else { 214 return new Promise((resolve, reject) => { 215 resolve(); 216 }) 217 } 218 }, 219 sendKeyFunction: function (...args) { 220 console.warn("TextInputClientMock.sendKeyFunction interface mocked in the Previewer. How this interface works on" + 221 " the Previewer may be different from that on a real device.") 222 const len = args.length 223 if (typeof args[len - 1] === 'function') { 224 args[len - 1].call(this, paramMock.businessErrorMock); 225 } else { 226 return new Promise((resolve, reject) => { 227 resolve(); 228 }) 229 } 230 }, 231 selectText: function (...args) { 232 console.warn("TextInputClientMock.selectText interface mocked in the Previewer. How this interface works on" + 233 " the Previewer may be different from that on a real device.") 234 const len = args.length 235 if (typeof args[len - 1] === 'function') { 236 args[len - 1].call(this, paramMock.businessErrorMock); 237 } else { 238 return new Promise((resolve, reject) => { 239 resolve(); 240 }) 241 } 242 }, 243 requestCurrentCursorContext: function (...args) { 244 console.warn("TextInputClientMock.requestCurrentCursorContext interface mocked in the Previewer. How this interface works on" + 245 " the Previewer may be different from that on a real device.") 246 const len = args.length 247 if (typeof args[len - 1] === 'function') { 248 args[len - 1].call(this, paramMock.businessErrorMock); 249 } else { 250 return new Promise((resolve, reject) => { 251 resolve(); 252 }) 253 } 254 }, 255 getAutoCapitalizeMode: function (...args) { 256 console.warn("TextInputClientMock.getAutoCapitalizeMode interface mocked in the Previewer. How this interface works on" + 257 " the Previewer may be different from that on a real device.") 258 const len = args.length 259 if (typeof args[len - 1] === 'function') { 260 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 261 } else { 262 return new Promise((resolve, reject) => { 263 resolve(paramMock.paramNumberMock); 264 }) 265 } 266 }, 267 reviseText: function (...args) { 268 console.warn("TextInputClientMock.reviseText interface mocked in the Previewer. How this interface works on" + 269 " the Previewer may be different from that on a real device.") 270 const len = args.length 271 if (typeof args[len - 1] === 'function') { 272 args[len - 1].call(this, paramMock.businessErrorMock); 273 } else { 274 return new Promise((resolve, reject) => { 275 resolve(); 276 }) 277 } 278 }, 279 markText: function (...args) { 280 console.warn("TextInputClientMock.markText interface mocked in the Previewer. How this interface works on" + 281 " the Previewer may be different from that on a real device.") 282 const len = args.length 283 if (typeof args[len - 1] === 'function') { 284 args[len - 1].call(this, paramMock.businessErrorMock); 285 } else { 286 return new Promise((resolve, reject) => { 287 resolve(); 288 }) 289 } 290 }, 291 unmarkText: function (...args) { 292 console.warn("TextInputClientMock.unmarkText interface mocked in the Previewer. How this interface works on" + 293 " the Previewer may be different from that on a real device.") 294 const len = args.length 295 if (typeof args[len - 1] === 'function') { 296 args[len - 1].call(this, paramMock.businessErrorMock); 297 } else { 298 return new Promise((resolve, reject) => { 299 resolve(); 300 }) 301 } 302 }, 303 replaceMarkedText: function (...args) { 304 console.warn("TextInputClientMock.replaceMarkedText interface mocked in the Previewer. How this interface works on" + 305 " the Previewer may be different from that on a real device.") 306 const len = args.length 307 if (typeof args[len - 1] === 'function') { 308 args[len - 1].call(this, paramMock.businessErrorMock); 309 } else { 310 return new Promise((resolve, reject) => { 311 resolve(); 312 }) 313 } 314 }, 315 moveCursor: function (...args) { 316 console.warn("TextInputClientMock.moveCursor interface mocked in the Previewer. How this interface works on" + 317 " the Previewer may be different from that on a real device.") 318 const len = args.length 319 if (typeof args[len - 1] === 'function') { 320 args[len - 1].call(this, paramMock.businessErrorMock); 321 } else { 322 return new Promise((resolve, reject) => { 323 resolve(); 324 }) 325 } 326 } 327 } 328 const InputMethodEngineMock = { 329 on: function (...args) { 330 console.warn("InputMethodEngine.on interface mocked in the Previewer. How this interface works on" + 331 " the Previewer may be different from that on a real device.") 332 const len = args.length 333 if (typeof args[len - 1] === 'function') { 334 if (args[0] == 'configurationUpdate') { 335 args[len - 1].call(this, paramMock.paramObjectMock); 336 } else if (args[0] == 'inputStart') { 337 args[len - 1].call(this, KeyboardControllerMock, TextInputClientMock); 338 } else if (args[0] == 'inputStop' || args[0] == 'keyboardShow' || args[0] == 'directionChange' || args[0] == 'keyboardHide') { 339 args[len - 1].call(this); 340 } else if (args[0] == 'setCallingWindow') { 341 args[len - 1].call(this, paramMock.paramNumberMock); 342 } 343 } 344 }, 345 off: function (...args) { 346 console.warn("InputMethodEngine.off interface mocked in the Previewer. How this interface works on" + 347 " the Previewer may be different from that on a real device.") 348 const len = args.length 349 if (typeof args[len - 1] === 'function') { 350 if (args[0] == 'configurationUpdate') { 351 args[len - 1].call(this, paramMock.paramObjectMock); 352 } else if (args[0] == 'inputStart') { 353 args[len - 1].call(this, KeyboardControllerMock, TextInputClientMock); 354 } else if (args[0] == 'inputStop' || args[0] == 'keyboardShow' || args[0] == 'directionChange' || args[0] == 'keyboardHide') { 355 args[len - 1].call(this); 356 } else if (args[0] == 'setCallingWindow') { 357 args[len - 1].call(this, paramMock.paramNumberMock); 358 } 359 } 360 } 361 } 362 const KeyboardDelegateMock = { 363 on: function (...args) { 364 console.warn("KeyboardDelegate.on interface mocked in the Previewer. How this interface works on" + 365 " the Previewer may be different from that on a real device.") 366 const len = args.length 367 if (typeof args[len - 1] === 'function') { 368 if (args[0] == 'keyDown' || args[0] == 'keyUp') { 369 args[len - 1].call(this, KeyEvent); 370 } else if (args[0] == 'selectionChange') { 371 args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock); 372 } else if (args[0] == 'cursorContextChange') { 373 args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock); 374 } else if (args[0] == 'textChange') { 375 args[len - 1].call(this, paramMock.paramStringMock); 376 } 377 } 378 }, 379 off: function (...args) { 380 console.warn("KeyboardDelegate.off interface mocked in the Previewer. How this interface works on" + 381 " the Previewer may be different from that on a real device.") 382 const len = args.length 383 if (typeof args[len - 1] === 'function') { 384 if (args[0] == 'keyDown' || args[0] == 'keyUp') { 385 args[len - 1].call(this, paramMock.paramObjectMock); 386 } else if (args[0] == 'selectionChange') { 387 args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock); 388 } else if (args[0] == 'cursorContextChange') { 389 args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock, paramMock.paramNumberMock); 390 } else if (args[0] == 'textChange') { 391 args[len - 1].call(this, paramMock.paramStringMock); 392 } 393 } 394 }, 395 } 396 const inputMethodEngine = { 397 getInputMethodEngine: function () { 398 console.warn("inputMethodEngine.getInputMethodEngine interface mocked in the Previewer. How this interface works" + 399 " on the Previewer may be different from that on a real device.") 400 return InputMethodEngineMock; 401 }, 402 createKeyboardDelegate: function () { 403 console.warn("inputMethodEngine.createKeyboardDelegate interface mocked in the Previewer. How this interface works" + 404 " on the Previewer may be different from that on a real device.") 405 return KeyboardDelegateMock; 406 }, 407 ENTER_KEY_TYPE_UNSPECIFIED: "[PC Preview] unknow ENTER_KEY_TYPE_UNSPECIFIED", 408 ENTER_KEY_TYPE_GO: "[PC Preview] unknow ENTER_KEY_TYPE_GO", 409 ENTER_KEY_TYPE_SEARCH: "[PC Preview] unknow ENTER_KEY_TYPE_SEARCH", 410 ENTER_KEY_TYPE_SEND: "[PC Preview] unknow ENTER_KEY_TYPE_SEND", 411 ENTER_KEY_TYPE_NEXT: "[PC Preview] unknow ENTER_KEY_TYPE_NEXT", 412 ENTER_KEY_TYPE_DONE: "[PC Preview] unknow ENTER_KEY_TYPE_DONE", 413 ENTER_KEY_TYPE_PREVIOUS: "[PC Preview] unknow ENTER_KEY_TYPE_PREVIOUS", 414 PATTERN_NULL: "[PC Preview] unknow PATTERN_NULL", 415 PATTERN_TEXT: "[PC Preview] unknow PATTERN_TEXT", 416 PATTERN_NUMBER: "[PC Preview] unknow PATTERN_NUMBER", 417 PATTERN_PHONE: "[PC Preview] unknow PATTERN_PHONE", 418 PATTERN_DATETIME: "[PC Preview] unknow PATTERN_DATETIME", 419 PATTERN_EMAIL: "[PC Preview] unknow PATTERN_EMAIL", 420 PATTERN_URI: "[PC Preview] unknow PATTERN_URI", 421 PATTERN_PASSWORD: "[PC Preview] unknow PATTERN_PASSWORD", 422 FLAG_SELECTING: "[PC Preview] unknow FLAG_SELECTING", 423 FLAG_SINGLE_LINE: "[PC Preview] unknow FLAG_SINGLE_LINE", 424 DISPLAY_MODE_PART: "[PC Preview] unknow DISPLAY_MODE_PART", 425 DISPLAY_MODE_FULL: "[PC Preview] unknow DISPLAY_MODE_FULL", 426 OPTION_ASCII: "[PC Preview] unknow OPTION_ASCII", 427 OPTION_NONE: "[PC Preview] unknow OPTION_NONE", 428 OPTION_AUTO_CAP_CHARACTERS: "[PC Preview] unknow OPTION_AUTO_CAP_CHARACTERS", 429 OPTION_AUTO_CAP_SENTENCES: "[PC Preview] unknow OPTION_AUTO_CAP_SENTENCES", 430 OPTION_AUTO_WORDS: "[PC Preview] unknow OPTION_AUTO_WORDS", 431 OPTION_MULTI_LINE: "[PC Preview] unknow OPTION_MULTI_LINE", 432 OPTION_NO_FULLSCREEN: "[PC Preview] unknow OPTION_NO_FULLSCREEN", 433 CURSOR_UP: "[PC Preview] unknow CURSOR_UP", 434 CURSOR_DOWN: "[PC Preview] unknow CURSOR_UP", 435 CURSOR_LEFT: "[PC Preview] unknow CURSOR_UP", 436 CURSOR_RIGHT: "[PC Preview] unknow CURSOR_UP", 437 WINDOW_TYPE_INPUT_METHOD_FLOAT: "[PC Preview] unknow WINDOW_TYPE_INPUT_METHOD_FLOAT" 438 } 439 return inputMethodEngine 440}