From b9e80b3e52e2749f85b2766cf4ad6abb98624f58 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Mon, 21 Mar 2022 19:36:48 +0800 Subject: [PATCH] aa Signed-off-by: liuyanzhi Change-Id: Id9a1af1d63f1f379d23b2c061e7dca7bb4edcbec --- .../napi/applicationServiceExtAbility.js | 2 +- ... => applicationServiceExtensionAbility.js} | 51 +++++++++++++------ .../main/extend/systemplugin/napi/index.js | 6 +-- 3 files changed, 40 insertions(+), 19 deletions(-) rename runtime/main/extend/systemplugin/napi/{applicationServiceExtension.js => applicationServiceExtensionAbility.js} (73%) diff --git a/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js b/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js index 8b6c8901..957f2a7f 100644 --- a/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js +++ b/runtime/main/extend/systemplugin/napi/applicationServiceExtAbility.js @@ -14,7 +14,7 @@ */ import { paramMock } from "../utils" -import { RemoteObjectClass } from "./applicationServiceExtension" +import { RemoteObjectClass } from "./applicationServiceExtensionAbility" const ApplicationInfoMock = { name: '[PC preview] unknow name', diff --git a/runtime/main/extend/systemplugin/napi/applicationServiceExtension.js b/runtime/main/extend/systemplugin/napi/applicationServiceExtensionAbility.js similarity index 73% rename from runtime/main/extend/systemplugin/napi/applicationServiceExtension.js rename to runtime/main/extend/systemplugin/napi/applicationServiceExtensionAbility.js index 812bfb5d..23146d19 100644 --- a/runtime/main/extend/systemplugin/napi/applicationServiceExtension.js +++ b/runtime/main/extend/systemplugin/napi/applicationServiceExtensionAbility.js @@ -90,7 +90,7 @@ export const RemoteObjectClass = class RemoteObject { }; } } -export function mockServiceExtension() { +export function mockServiceExtensionAbility() { const IRemoteBrokerMock = { asObject: function () { console.warn("IRemoteBroker.asObject interface mocked in the Previewer. How this interface works on the Previewer" + @@ -135,10 +135,22 @@ export function mockServiceExtension() { const serviceExtensionContextClass = class serviceExtensionContext extends ExtensionContextClass { constructor() { super(); - console.warn('ServiceExtension.serviceExtensionContext.constructor interface mocked in the Previewer. How this interface works on' + + console.warn('ServiceExtensionAbility.serviceExtensionContext.constructor interface mocked in the Previewer. How this interface works on' + ' the Previewer may be different from that on a real device.'); this.startAbility = function (...args) { - console.warn("ServiceExtension.serviceExtensionContext.startAbility interface mocked in the Previewer." + + console.warn("ServiceExtensionAbility.serviceExtensionContext.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(); + }) + } + }; + this.startAbilityWithAccount = function (...args) { + console.warn("ServiceExtensionAbility.serviceExtensionContext.startAbilityWithAccount 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') { @@ -150,7 +162,7 @@ export function mockServiceExtension() { } }; this.terminateSelf = function (...args) { - console.warn("ServiceExtension.serviceExtensionContext.terminateSelf interface mocked in the Previewer." + + console.warn("ServiceExtensionAbility.serviceExtensionContext.terminateSelf 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') { @@ -162,12 +174,17 @@ export function mockServiceExtension() { } }; this.connectAbility = function (...args) { - console.warn("ServiceExtension.serviceExtensionContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("ServiceExtensionAbility.serviceExtensionContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") + return paramMock.paramNumberMock + }; + this.connectAbilityWithAccount = function (...args) { + console.warn("ServiceExtensionAbility.serviceExtensionContext.connectAbilityWithAccount interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") return paramMock.paramNumberMock }; this.disconnectAbility = function (...args) { - console.warn("ServiceExtension.serviceExtensionContext.disconnectAbility interface mocked in the Previewer." + + console.warn("ServiceExtensionAbility.serviceExtensionContext.disconnectAbility 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') { @@ -180,37 +197,41 @@ export function mockServiceExtension() { } } } - const ServiceExtensionClass = class ServiceExtension { + const ServiceExtensionAbilityClass = class ServiceExtensionAbility { constructor() { - console.warn('application.ServiceExtension.constructor interface mocked in the Previewer. How this interface works on' + + console.warn('application.ServiceExtensionAbility.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 serviceExtensionContextClass(); this.onCreate = function (...args) { - console.warn("application.ServiceExtension.onCreate interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onCreate 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.ServiceExtension.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") }; this.onRequest = function (...args) { - console.warn("application.ServiceExtension.onRequest interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onRequest interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") }; this.onConnect = function (...args) { - console.warn("application.ServiceExtension.onConnect interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onConnect interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") return new RemoteObjectClass(); }; this.onDisconnect = function (...args) { - console.warn("application.ServiceExtension.onDisconnect interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onDisconnect interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") }; this.onReconnect = function (...args) { - console.warn("application.ServiceExtension.onReconnect interface mocked in the Previewer. How this interface works on the Previewer" + + console.warn("application.ServiceExtensionAbility.onReconnect 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.ServiceExtensionAbility.onConfigurationUpdated interface mocked in the Previewer. How this interface works on the Previewer" + " may be different from that on a real device.") }; } } - return new ServiceExtensionClass(); + return new ServiceExtensionAbilityClass(); } \ 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 03cd233f..ca840a0f 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -16,7 +16,7 @@ import { mockSystemParameter } from './systemParameter' import { mockAbility } from './applicationAbility' import { mockFormExtension } from './applicationFormExtension' -import { mockServiceExtension } from './applicationServiceExtension' +import { mockServiceExtensionAbility } from './applicationServiceExtensionAbility' import { mockAbilityStage } from './applicationAbilityStage' import { mockFormBindingData } from './applicationFormBindingData' import { mockAbilityManager } from './applicationAbilityManager' @@ -100,8 +100,8 @@ export function mockRequireNapiFun() { return mockAbility(); case "application.FormExtension": return mockFormExtension(); - case "application.ServiceExtension": - return mockServiceExtension(); + case "application.ServiceExtensionAbility": + return mockServiceExtensionAbility(); case "application.AbilityStage": return mockAbilityStage(); case "application.formBindingData":