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" 17import { AbilityContextClass } from "./application/abilityContext" 18 19const WantClass = class Want { 20 constructor() { 21 console.warn('Ability.Want.constructor interface mocked in the Previewer. How this interface works on' + 22 ' the Previewer may be different from that on a real device.'); 23 this.deviceId = "[PC Preview] unknow deviceId"; 24 this.bundleName = "[PC Preview] unknow bundleName"; 25 this.abilityName = "[PC Preview] unknow abilityName"; 26 this.uri = "[PC Preview] unknow uri"; 27 this.type = "[PC Preview] unknow type"; 28 this.flag = "[PC Preview] unknow flag"; 29 this.action = "[PC Preview] unknow action"; 30 this.parameters = {}; 31 this.entities = [paramMock.paramStringMock]; 32 } 33} 34const calleeMock = { 35 on: function (...args) { 36 console.warn("Ability.calleeClass.on interface mocked in the Previewer. How this interface works on the Previewer" + 37 " may be different from that on a real device.") 38 }, 39 off: function (...args) { 40 console.warn("Ability.calleeClass.off interface mocked in the Previewer. How this interface works on the Previewer" + 41 " may be different from that on a real device.") 42 }, 43} 44export function mockAbility() { 45 const AbilityClass = class Ability { 46 constructor() { 47 console.warn('application.Ability.constructor interface mocked in the Previewer. How this interface works on' + 48 ' the Previewer may be different from that on a real device.'); 49 this.context = new AbilityContextClass(); 50 this.launchWant = new WantClass(); 51 this.lastRequestWant = new WantClass(); 52 this.callee = calleeMock; 53 this.onCreate = function (...args) { 54 console.warn("application.Ability.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + 55 " may be different from that on a real device.") 56 }; 57 this.onWindowStageCreate = function (...args) { 58 console.warn("application.Ability.onWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" + 59 " may be different from that on a real device.") 60 }; 61 this.onWindowStageDestroy = function () { 62 console.warn("application.Ability.onWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" + 63 " may be different from that on a real device.") 64 }; 65 this.onDestroy = function () { 66 console.warn("application.Ability.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + 67 " may be different from that on a real device.") 68 }; 69 this.onForeground = function () { 70 console.warn("application.Ability.onForeground interface mocked in the Previewer. How this interface works on the Previewer" + 71 " may be different from that on a real device.") 72 }; 73 this.onBackground = function () { 74 console.warn("application.Ability.onBackground interface mocked in the Previewer. How this interface works on the Previewer" + 75 " may be different from that on a real device.") 76 }; 77 this.onContinue = function () { 78 console.warn("application.Ability.onContinue interface mocked in the Previewer. How this interface works on the Previewer" + 79 " may be different from that on a real device.") 80 return paramMock.paramBooleanMock; 81 }; 82 this.onNewWant = function () { 83 console.warn("application.Ability.onNewWant interface mocked in the Previewer. How this interface works on the Previewer" + 84 " may be different from that on a real device.") 85 }; 86 this.onConfigurationUpdated = function () { 87 console.warn("application.Ability.onConfigurationUpdated interface mocked in the Previewer. How this interface works on the Previewer" + 88 " may be different from that on a real device.") 89 }; 90 } 91 } 92 return new AbilityClass(); 93} 94