From 579e09408b7f25f9e6e1c7319237394ce4e4adf5 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 7 Jul 2022 21:30:04 +0800 Subject: [PATCH] application mock Signed-off-by: liuyanzhi Change-Id: I2cf2fcc8df92d41e6a7014e9b316b5d4a2b3c1d9 --- runtime/main/extend/systemplugin/ability.js | 26 +-- runtime/main/extend/systemplugin/index.js | 2 - .../napi/application/abilityDelegator.js | 155 ++++++++++++++++++ .../napi/application/abilityDelegatorArgs.js | 21 +++ .../napi/application/shellCmdResult.js | 19 +++ .../main/extend/systemplugin/napi/index.js | 11 +- .../napi/ohos_ability_dataUriUtils.js | 42 +++++ .../napi/ohos_application_Ability.js | 122 +++++++------- .../napi/ohos_application_AbilityConstant.js | 20 +++ ...os_application_AbilityLifecycleCallback.js | 54 ++++++ .../napi/ohos_application_Want.js | 32 ++++ ...os_application_abilityDelegatorRegistry.js | 41 +++++ 12 files changed, 454 insertions(+), 91 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/application/abilityDelegator.js create mode 100644 runtime/main/extend/systemplugin/napi/application/abilityDelegatorArgs.js create mode 100644 runtime/main/extend/systemplugin/napi/application/shellCmdResult.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_ability_dataUriUtils.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_AbilityConstant.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_AbilityLifecycleCallback.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_Want.js create mode 100644 runtime/main/extend/systemplugin/napi/ohos_application_abilityDelegatorRegistry.js diff --git a/runtime/main/extend/systemplugin/ability.js b/runtime/main/extend/systemplugin/ability.js index e69545de..64ecc6d8 100644 --- a/runtime/main/extend/systemplugin/ability.js +++ b/runtime/main/extend/systemplugin/ability.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1355,30 +1355,6 @@ export function mockAbilityContinuationRegisterManager() { } } } -export function mockAbilityDataUriUtils() { - global.systemplugin.ability.dataUriUtils = { - getId: function (...args) { - console.warn("ability.dataUriUtils.getId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return paramMock.paramNumberMock - }, - attachId: function (...args) { - console.warn("ability.dataUriUtils.attachId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return paramMock.paramStringMock - }, - deleteId: function (...args) { - console.warn("ability.dataUriUtils.deleteId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return paramMock.paramStringMock - }, - updateId: function (...args) { - console.warn("ability.dataUriUtils.updateId interface mocked in the Previewer. How this interface works" + - " on the Previewer may be different from that on a real device.") - return paramMock.paramStringMock - } - } -} export function mockAbilityAbilityAgent() { global.systemplugin.ability.abilityAgent = { on: function (...args) { diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index aa9b3208..6bb85b48 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -20,7 +20,6 @@ import { mockAbilityParticleAbility, mockAbilityFormManager, mockAbilityContinuationRegisterManager, - mockAbilityDataUriUtils, mockAbilityAbilityAgent, mockAbilityFormBindingData } from './ability' @@ -73,7 +72,6 @@ export function mockSystemPlugin() { mockAbilityFeatureAbility() mockAbilityContinuationRegisterManager() mockRequireNapiFun() - mockAbilityDataUriUtils() mockAccessibility() mockAbilityParticleAbility() mockAbilityFormManager() diff --git a/runtime/main/extend/systemplugin/napi/application/abilityDelegator.js b/runtime/main/extend/systemplugin/napi/application/abilityDelegator.js new file mode 100644 index 00000000..fb5d7fa1 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/application/abilityDelegator.js @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { paramMock } from "../../utils" +import { AbilityClass } from "../ohos_application_Ability" +import { ContextClass } from "../ohos_application_ServiceExtAbility" +import { ShellCmdResult } from "./shellCmdResult" + +export const AbilityDelegator = { + addAbilityMonitor: function (...args) { + console.warn("AbilityDelegator.addAbilityMonitor interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + removeAbilityMonitor: function (...args) { + console.warn("AbilityDelegator.removeAbilityMonitor interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + waitAbilityMonitor: function (...args) { + console.warn("AbilityDelegator.waitAbilityMonitor interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new AbilityClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new AbilityClass()); + }) + } + }, + getAppContext: function (...args) { + console.warn('AbilityDelegator.getAppContext interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return new ContextClass(); + }, + getAbilityState: function (...args) { + console.warn('AbilityDelegator.getAbilityState interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return paramMock.paramNumberMock; + }, + getCurrentTopAbility: function (...args) { + console.warn("AbilityDelegator.getCurrentTopAbility interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, new AbilityClass()); + } else { + return new Promise((resolve, reject) => { + resolve(new AbilityClass()); + }) + } + }, + startAbility: function (...args) { + console.warn("AbilityDelegator.startAbility interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + doAbilityForeground: function (...args) { + console.warn("AbilityDelegator.doAbilityForeground interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + doAbilityBackground: function (...args) { + console.warn("AbilityDelegator.doAbilityBackground interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + print: function (...args) { + console.warn("AbilityDelegator.print interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + }, + printSync: function (...args) { + console.warn('AbilityDelegator.printSync interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + }, + executeShellCommand: function (...args) { + console.warn("AbilityDelegator.executeShellCommand interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, ShellCmdResult); + } else { + return new Promise((resolve, reject) => { + resolve(ShellCmdResult); + }) + } + }, + finishTest: function (...args) { + console.warn("AbilityDelegator.finishTest interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + const len = args.length + if (len > 0 && typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock); + } else { + return new Promise((resolve, reject) => { + resolve(); + }) + } + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/application/abilityDelegatorArgs.js b/runtime/main/extend/systemplugin/napi/application/abilityDelegatorArgs.js new file mode 100644 index 00000000..104b0367 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/application/abilityDelegatorArgs.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const AbilityDelegatorArgs = { + bundleName: "[PC Preview] unknow bundleName", + parameters: {}, + testCaseNames: "[PC Preview] unknow testCaseNames", + testRunnerClassName: "[PC Preview] unknow testRunnerClassName", +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/application/shellCmdResult.js b/runtime/main/extend/systemplugin/napi/application/shellCmdResult.js new file mode 100644 index 00000000..920d25dd --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/application/shellCmdResult.js @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const ShellCmdResult = { + stdResult: "[PC Preview] unknow stdResult", + exitCode: "[PC Preview] unknow exitCode", +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 92e0645c..0401d174 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -15,6 +15,9 @@ import { mockSystemParameter } from './ohos_systemparameter' import { mockAbility } from './ohos_application_Ability' +import { mockDataUriUtils } from './ohos_ability_dataUriUtils' +import { mockAbilityDelegatorRegistry } from './ohos_application_abilityDelegatorRegistry' +import { mockAbilityLifecycleCallback } from './ohos_application_AbilityLifecycleCallback' import { mockFormExtension } from './ohos_application_FormExtension' import { mockServiceExtensionAbility } from './ohos_application_ServiceExtensionAbility' import { mockAbilityStage } from './ohos_application_AbilityStage' @@ -252,12 +255,18 @@ export function mockRequireNapiFun() { return mockOhosBatteryinfo(); case "systemParameter": return mockSystemParameter(); - case "11.Ability": + case "ability.dataUriUtils": + return mockDataUriUtils(); + case "application.Ability": return mockAbility(); case "application.FormExtension": return mockFormExtension(); case "application.ServiceExtensionAbility": return mockServiceExtensionAbility(); + case "application.abilityDelegatorRegistry": + return mockAbilityDelegatorRegistry(); + case "application.AbilityLifecycleCallback": + return mockAbilityLifecycleCallback(); case "application.AbilityStage": return mockAbilityStage(); case "application.formBindingData": diff --git a/runtime/main/extend/systemplugin/napi/ohos_ability_dataUriUtils.js b/runtime/main/extend/systemplugin/napi/ohos_ability_dataUriUtils.js new file mode 100644 index 00000000..9ed2ad00 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_ability_dataUriUtils.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockDataUriUtils() { + const dataUriUtils = { + getId: function (...args) { + console.warn("dataUriUtils.getId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramNumberMock + }, + attachId: function (...args) { + console.warn("dataUriUtils.attachId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + deleteId: function (...args) { + console.warn("dataUriUtils.deleteId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + }, + updateId: function (...args) { + console.warn("dataUriUtils.updateId interface mocked in the Previewer. How this interface works" + + " on the Previewer may be different from that on a real device.") + return paramMock.paramStringMock + } + } + return dataUriUtils; +} diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_Ability.js b/runtime/main/extend/systemplugin/napi/ohos_application_Ability.js index 7402c1bb..51b30eb8 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_application_Ability.js +++ b/runtime/main/extend/systemplugin/napi/ohos_application_Ability.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,22 +15,9 @@ import { paramMock } from "../utils" import { AbilityContextClass } from "./application/abilityContext" +import { WantClass } from "./ohos_application_Want" +import { OnContinueResult } from "./ohos_application_AbilityConstant" -const WantClass = class Want { - constructor() { - console.warn('Ability.Want.constructor interface mocked in the Previewer. How this interface works on' + - ' the Previewer may be different from that on a real device.'); - this.deviceId = "[PC Preview] unknow deviceId"; - this.bundleName = "[PC Preview] unknow bundleName"; - this.abilityName = "[PC Preview] unknow abilityName"; - this.uri = "[PC Preview] unknow uri"; - this.type = "[PC Preview] unknow type"; - this.flag = "[PC Preview] unknow flag"; - this.action = "[PC Preview] unknow action"; - this.parameters = {}; - this.entities = [paramMock.paramStringMock]; - } -} const calleeMock = { on: function (...args) { console.warn("Ability.calleeClass.on interface mocked in the Previewer. How this interface works on the Previewer" + @@ -41,53 +28,62 @@ const calleeMock = { " may be different from that on a real device.") }, } -export function mockAbility() { - const AbilityClass = class Ability { - constructor() { - console.warn('application.Ability.constructor interface mocked in the Previewer. How this interface works on' + - ' the Previewer may be different from that on a real device.'); - this.context = new AbilityContextClass(); - this.launchWant = new WantClass(); - this.lastRequestWant = new WantClass(); - this.callee = calleeMock; - this.onCreate = function (...args) { - console.warn("application.Ability.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onWindowStageCreate = function (...args) { - console.warn("application.Ability.onWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onWindowStageDestroy = function () { - console.warn("application.Ability.onWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onDestroy = function () { - console.warn("application.Ability.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onForeground = function () { - console.warn("application.Ability.onForeground interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onBackground = function () { - console.warn("application.Ability.onBackground interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onContinue = function () { - console.warn("application.Ability.onContinue interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - return paramMock.paramBooleanMock; - }; - this.onNewWant = function () { - console.warn("application.Ability.onNewWant interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - this.onConfigurationUpdated = function () { - console.warn("application.Ability.onConfigurationUpdated interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device.") - }; - } +export const AbilityClass = class Ability { + constructor() { + console.warn('application.Ability.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.context = new AbilityContextClass(); + this.launchWant = new WantClass(); + this.lastRequestWant = new WantClass(); + this.callee = calleeMock; + this.onCreate = function (...args) { + console.warn("application.Ability.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onWindowStageCreate = function (...args) { + console.warn("application.Ability.onWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onWindowStageDestroy = function () { + console.warn("application.Ability.onWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onWindowStageRestore = function (...args) { + console.warn("application.Ability.onWindowStageRestore interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onDestroy = function () { + console.warn("application.Ability.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onForeground = function () { + console.warn("application.Ability.onForeground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onBackground = function () { + console.warn("application.Ability.onBackground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onContinue = function (...args) { + console.warn("application.Ability.onContinue interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return OnContinueResult; + }; + this.onNewWant = function (...args) { + console.warn("application.Ability.onNewWant interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onConfigurationUpdated = function (...args) { + console.warn("application.Ability.onConfigurationUpdated interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.dump = function (...args) { + console.warn("application.Ability.dump interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return [paramMock.paramStringMock]; + }; } +} +export function mockAbility() { return new AbilityClass(); } diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_AbilityConstant.js b/runtime/main/extend/systemplugin/napi/ohos_application_AbilityConstant.js new file mode 100644 index 00000000..4d1f9623 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_AbilityConstant.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const OnContinueResult = { + AGREE: 0, + REJECT: 1, + MISMATCH: 2, +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_AbilityLifecycleCallback.js b/runtime/main/extend/systemplugin/napi/ohos_application_AbilityLifecycleCallback.js new file mode 100644 index 00000000..511379ed --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_AbilityLifecycleCallback.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { paramMock } from "../utils" + +export function mockAbilityLifecycleCallback() { + const AbilityLifecycleCallbackClass = class AbilityLifecycleCallback { + constructor() { + console.warn('application.AbilityLifecycleCallback.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.onAbilityCreate = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityWindowStageCreate = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityWindowStageDestroy = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityDestroy = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityForeground = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityForeground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityBackground = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityBackground interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + this.onAbilityContinue = function (...args) { + console.warn("application.AbilityLifecycleCallback.onAbilityContinue interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + }; + } + } + return new AbilityLifecycleCallbackClass(); +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_Want.js b/runtime/main/extend/systemplugin/napi/ohos_application_Want.js new file mode 100644 index 00000000..1fad9fd2 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_Want.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { paramMock } from "../utils" + +export const WantClass = class Want { + constructor() { + console.warn('Want.constructor interface mocked in the Previewer. How this interface works on' + + ' the Previewer may be different from that on a real device.'); + this.deviceId = "[PC Preview] unknow deviceId"; + this.bundleName = "[PC Preview] unknow bundleName"; + this.abilityName = "[PC Preview] unknow abilityName"; + this.uri = "[PC Preview] unknow uri"; + this.type = "[PC Preview] unknow type"; + this.flag = "[PC Preview] unknow flag"; + this.action = "[PC Preview] unknow action"; + this.parameters = {}; + this.entities = [paramMock.paramStringMock]; + this.moduleName = "[PC Preview] unknow moduleName"; + } +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_application_abilityDelegatorRegistry.js b/runtime/main/extend/systemplugin/napi/ohos_application_abilityDelegatorRegistry.js new file mode 100644 index 00000000..6b3df79d --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_application_abilityDelegatorRegistry.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityDelegator } from "./application/abilityDelegator" +import { AbilityDelegatorArgs } from "./application/abilityDelegatorArgs" + +export const AbilityLifecycleState = { + UNINITIALIZED: '[PC preview] unknow UNINITIALIZED', + CREATE: '[PC preview] unknow CREATE', + FOREGROUND: '[PC preview] unknow FOREGROUND', + BACKGROUND: '[PC preview] unknow BACKGROUND', + DESTROY: '[PC preview] unknow DESTROY', +} + +export function mockAbilityDelegatorRegistry() { + const abilityDelegatorRegistry = { + getAbilityDelegator: function () { + console.warn('abilityDelegatorRegistry.getAbilityDelegator interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return AbilityDelegator; + }, + getArguments: function () { + console.warn('abilityDelegatorRegistry.getArguments interface mocked in the Previewer. How this interface works on the' + + ' Previewer may be different from that on a real device.'); + return AbilityDelegatorArgs; + }, + } + return abilityDelegatorRegistry +} \ No newline at end of file