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" 17import { AbilityRunningInfo as _AbilityRunningInfo } from "./application/AbilityRunningInfo" 18import { ExtensionRunningInfo as _ExtensionRunningInfo } from "./application/ExtensionRunningInfo" 19import { ElementName } from "./bundle/elementName" 20 21export const AbilityState = { 22 INITIAL: 0, 23 FOREGROUND: 9, 24 BACKGROUND: 10, 25 FOREGROUNDING: 11, 26 BACKGROUNDING: 12 27} 28export function mockAbilityManager() { 29 const abilityManager = { 30 AbilityState, 31 updateConfiguration: function (...args) { 32 console.warn('abilityManager.updateConfiguration interface mocked in the Previewer. How this interface works on the' + 33 ' Previewer may be different from that on a real device.'); 34 const len = args.length; 35 if (typeof args[len - 1] === 'function') { 36 args[len - 1].call(this, paramMock.businessErrorMock); 37 } else { 38 return new Promise((resolve) => { 39 resolve(); 40 }); 41 } 42 }, 43 getAbilityRunningInfos: function (...args) { 44 console.warn('abilityManager.getAbilityRunningInfos interface mocked in the Previewer. How this interface works on the' + 45 ' Previewer may be different from that on a real device.'); 46 const len = args.length; 47 if (typeof args[len - 1] === 'function') { 48 args[len - 1].call(this, paramMock.businessErrorMock, [_AbilityRunningInfo]); 49 } else { 50 return new Promise((resolve) => { 51 resolve([_AbilityRunningInfo]); 52 }); 53 } 54 }, 55 getExtensionRunningInfos: function (...args) { 56 console.warn('abilityManager.getExtensionRunningInfos interface mocked in the Previewer. How this interface works on the' + 57 ' Previewer may be different from that on a real device.'); 58 const len = args.length; 59 if (typeof args[len - 1] === 'function') { 60 args[len - 1].call(this, paramMock.businessErrorMock, [_ExtensionRunningInfo]); 61 } else { 62 return new Promise((resolve) => { 63 resolve([_ExtensionRunningInfo]); 64 }); 65 } 66 }, 67 getTopAbility: function (...args) { 68 console.warn('abilityManager.getTopAbility interface mocked in the Previewer. How this interface works on the' + 69 ' Previewer may be different from that on a real device.'); 70 const len = args.length; 71 if (typeof args[len - 1] === 'function') { 72 args[len - 1].call(this, paramMock.businessErrorMock, ElementName); 73 } else { 74 return new Promise((resolve) => { 75 resolve(ElementName); 76 }); 77 } 78 }, 79 AbilityRunningInfo: _AbilityRunningInfo, 80 ExtensionRunningInfo: _ExtensionRunningInfo 81 } 82 return abilityManager 83}