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 16import { paramMock } from "../utils" 17 18export function mockInputEventClient() { 19 const KeyEvent = { 20 isPressed: '[PC preview] unknow isPressed', 21 keyCode: '[PC preview] unknow keyCode', 22 keyDownDuration: '[PC preview] unknow keyDownDuration', 23 isIntercepted: '[PC preview] unknow isIntercepted', 24 } 25 const inputEventClient = { 26 injectEvent: function(...args) { 27 console.warn("inputEventClient.injectEvent interface mocked in the Previewer. How this interface works on the" + 28 " Previewer may be different from that on a real device."); 29 const len = args.length; 30 if (len !== 1) { 31 console.warn("the number of parameter must be one"); 32 return; 33 } 34 if (typeof args[0] !== 'object') { 35 console.warn("the second parameter type must be 'object'"); 36 return; 37 } 38 if (!('KeyEvent' in args[0])) { 39 console.warn("missing 'KeyEvent' field"); 40 return; 41 } 42 if (typeof args[0].KeyEvent.isPressed !== 'boolean') { 43 console.warn("Field isPressed must be boolean"); 44 return; 45 } 46 if (typeof args[0].KeyEvent.keyCode !== 'number') { 47 console.warn("Field keyCode must be number"); 48 return; 49 } 50 if (typeof args[0].KeyEvent.keyDownDuration !== 'number') { 51 console.warn("Field keyDownDuration must be number"); 52 return; 53 } 54 if (typeof args[0].KeyEvent.isIntercepted !== 'boolean') { 55 console.warn("Field isIntercepted must be boolean"); 56 return; 57 } 58 args[0].call(this, paramMock.businessErrorMock); 59 } 60 } 61 return inputEventClient; 62}