mirror of
https://github.com/openharmony/third_party_jsframework.git
synced 2026-07-19 14:33:33 -04:00
!191 添加context和AbilityContext接口mock
Merge pull request !191 from liuyanzhi2020/liu0228
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
|
||||
import { paramMock } from "../../utils"
|
||||
import { MessageParcelClass } from "../rpc"
|
||||
import { ContextClass } from "../applicationServiceExtAbility"
|
||||
|
||||
const ModuleInfoMock = {
|
||||
moduleName: '[PC preview] unknow moduleName',
|
||||
@@ -219,23 +221,7 @@ const resourceManagerMock = {
|
||||
}
|
||||
},
|
||||
}
|
||||
export const contextClass = class context {
|
||||
constructor() {
|
||||
console.warn('context.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.resourceManager = resourceManagerMock;
|
||||
this.applicationInfo = applicationInfoMock;
|
||||
this.HapModuleInfo = HapModuleInfoMock;
|
||||
this.cacheDir = '[PC preview] unknow cacheDir';
|
||||
this.tempDir = '[PC preview] unknow tempDir';
|
||||
this.filesDir = '[PC preview] unknow filesDir';
|
||||
this.databaseDir = '[PC preview] unknow databaseDir';
|
||||
this.storageDir = '[PC preview] unknow storageDir';
|
||||
this.bundleCodeDir = '[PC preview] unknow bundleCodeDir';
|
||||
this.distributedFilesDir = '[PC preview] unknow distributedFilesDir';
|
||||
}
|
||||
};
|
||||
export const abilityStageContextClass = class abilityStageContext extends contextClass {
|
||||
export const abilityStageContextClass = class abilityStageContext extends ContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
console.warn('Context.abilityStageContext.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
@@ -243,7 +229,7 @@ export const abilityStageContextClass = class abilityStageContext extends contex
|
||||
this.currentHapModuleInfo = HapModuleInfoMock;
|
||||
}
|
||||
}
|
||||
export const ExtensionContextClass = class ExtensionContext extends contextClass {
|
||||
export const ExtensionContextClass = class ExtensionContext extends ContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
console.warn('Context.ExtensionContext.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
@@ -254,13 +240,45 @@ export const ExtensionContextClass = class ExtensionContext extends contextClass
|
||||
export const AbilityResultMock = {
|
||||
resultCode: "[PC Preview] unknow resultCode",
|
||||
}
|
||||
export const AbilityContextClass = class AbilityContext extends contextClass {
|
||||
const ConfigurationMock = {
|
||||
language: '[PC preview] unknow language'
|
||||
}
|
||||
const PermissionRequestResultMock = {
|
||||
permissions: [paramMock.paramStringMock],
|
||||
authResults: [paramMock.paramNumberMock]
|
||||
}
|
||||
const CallerMock = {
|
||||
call: function (...args) {
|
||||
console.warn("AbilityContext.Caller.call interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve();
|
||||
})
|
||||
},
|
||||
callWithResult: function (...args) {
|
||||
console.warn("AbilityContext.Caller.callWithResult interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(new MessageParcelClass());
|
||||
})
|
||||
},
|
||||
release: function (...args) {
|
||||
console.warn("AbilityContext.Caller.release interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
},
|
||||
onRelease: function (...args) {
|
||||
console.warn("AbilityContext.Caller.onRelease interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
},
|
||||
}
|
||||
export const AbilityContextClass = class AbilityContext extends ContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
console.warn('Ability.AbilityContext.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.abilityInfo = AbilityInfoMock;
|
||||
this.currentHapModuleInfo = HapModuleInfoMock;
|
||||
this.config = ConfigurationMock;
|
||||
this.startAbility = function (...args) {
|
||||
console.warn("Ability.AbilityContext.startAbility interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
@@ -273,6 +291,25 @@ export const AbilityContextClass = class AbilityContext extends contextClass {
|
||||
})
|
||||
}
|
||||
};
|
||||
this.startAbilityByCall = function (...args) {
|
||||
console.warn("Ability.AbilityContext.startAbilityByCall interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(CallerMock);
|
||||
})
|
||||
};
|
||||
this.startAbilityWithAccount = function (...args) {
|
||||
console.warn("Ability.AbilityContext.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') {
|
||||
args[len - 1].call(this, paramMock.businessErrorMock);
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve();
|
||||
})
|
||||
}
|
||||
};
|
||||
this.startAbilityForResult = function (...args) {
|
||||
console.warn("Ability.AbilityContext.startAbilityForResult interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
@@ -285,6 +322,18 @@ export const AbilityContextClass = class AbilityContext extends contextClass {
|
||||
})
|
||||
}
|
||||
};
|
||||
this.startAbilityForResultWithAccount = function (...args) {
|
||||
console.warn("Ability.AbilityContext.startAbilityForResultWithAccount 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, AbilityResultMock);
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(AbilityResultMock);
|
||||
})
|
||||
}
|
||||
};
|
||||
this.terminateSelf = function (...args) {
|
||||
console.warn("Ability.AbilityContext.terminateSelf interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
@@ -314,6 +363,11 @@ export const AbilityContextClass = class AbilityContext extends contextClass {
|
||||
" may be different from that on a real device.")
|
||||
return paramMock.paramNumberMock
|
||||
};
|
||||
this.connectAbilityWithAccount = function (...args) {
|
||||
console.warn("Ability.AbilityContext.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("Ability.AbilityContext.disconnectAbility interface mocked in the Previewer." +
|
||||
" How this interface works on the Previewer may be different from that on a real device.")
|
||||
@@ -326,6 +380,30 @@ export const AbilityContextClass = class AbilityContext extends contextClass {
|
||||
})
|
||||
}
|
||||
};
|
||||
this.setMissionLabel = function (...args) {
|
||||
console.warn("Ability.AbilityContext.setMissionLabel 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.requestPermissionsFromUser = function (...args) {
|
||||
console.warn("Ability.AbilityContext.requestPermissionsFromUser 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, PermissionRequestResultMock);
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(PermissionRequestResultMock);
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
export function mockAbilityContext() {
|
||||
|
||||
@@ -16,28 +16,83 @@
|
||||
import { paramMock } from "../utils"
|
||||
import { RemoteObjectClass } from "./applicationServiceExtension"
|
||||
|
||||
export function mockServiceExtAbility() {
|
||||
const ApplicationInfoMock = {
|
||||
name: '[PC preview] unknow name',
|
||||
description: '[PC preview] unknow description',
|
||||
descriptionId: '[PC preview] unknow descriptionId',
|
||||
systemApp: '[PC preview] unknow systemApp',
|
||||
enabled: '[PC preview] unknow enabled',
|
||||
label: '[PC preview] unknow label',
|
||||
labelId: '[PC preview] unknow labelId',
|
||||
icon: '[PC preview] unknow icon',
|
||||
iconId: '[PC preview] unknow iconId',
|
||||
process: '[PC preview] unknow process',
|
||||
supportedModes: '[PC preview] unknow supportedModes',
|
||||
moduleSourceDirs: [paramMock.paramStringMock],
|
||||
permissions: [paramMock.paramStringMock],
|
||||
entryDir: '[PC preview] unknow entryDir',
|
||||
codePath: '[PC preview] unknow codePath',
|
||||
removable: '[PC preview] unknow removable',
|
||||
accessTokenId: '[PC preview] unknow accessTokenId',
|
||||
uid: '[PC preview] unknow uid',
|
||||
entityType: '[PC preview] unknow entityType'
|
||||
const ApplicationInfoMock = {
|
||||
name: '[PC preview] unknow name',
|
||||
description: '[PC preview] unknow description',
|
||||
descriptionId: '[PC preview] unknow descriptionId',
|
||||
systemApp: '[PC preview] unknow systemApp',
|
||||
enabled: '[PC preview] unknow enabled',
|
||||
label: '[PC preview] unknow label',
|
||||
labelId: '[PC preview] unknow labelId',
|
||||
icon: '[PC preview] unknow icon',
|
||||
iconId: '[PC preview] unknow iconId',
|
||||
process: '[PC preview] unknow process',
|
||||
supportedModes: '[PC preview] unknow supportedModes',
|
||||
moduleSourceDirs: [paramMock.paramStringMock],
|
||||
permissions: [paramMock.paramStringMock],
|
||||
entryDir: '[PC preview] unknow entryDir',
|
||||
codePath: '[PC preview] unknow codePath',
|
||||
removable: '[PC preview] unknow removable',
|
||||
accessTokenId: '[PC preview] unknow accessTokenId',
|
||||
uid: '[PC preview] unknow uid',
|
||||
entityType: '[PC preview] unknow entityType'
|
||||
}
|
||||
const EventHubClass = class EventHub {
|
||||
constructor() {
|
||||
console.warn('EventHub.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.on = function (...args) {
|
||||
console.warn("EventHub.on interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
};
|
||||
this.off = function (...args) {
|
||||
console.warn("EventHub.off interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
};
|
||||
this.emit = function (...args) {
|
||||
console.warn("EventHub.emit interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
};
|
||||
}
|
||||
}
|
||||
const BaseContextClass = class BaseContext {
|
||||
constructor() {
|
||||
console.warn('BaseContext.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.stageMode = "[PC Preview] unknow stageMode";
|
||||
}
|
||||
}
|
||||
export const ContextClass = class Context extends BaseContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
console.warn('Context.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.applicationInfo = ApplicationInfoMock;
|
||||
this.cacheDir = "[PC Preview] unknow cacheDir";
|
||||
this.tempDir = "[PC Preview] unknow tempDir";
|
||||
this.filesDir = "[PC Preview] unknow filesDir";
|
||||
this.databaseDir = "[PC Preview] unknow databaseDir";
|
||||
this.storageDir = "[PC Preview] unknow storageDir";
|
||||
this.bundleCodeDir = "[PC Preview] unknow bundleCodeDir";
|
||||
this.distributedFilesDir = "[PC Preview] unknow distributedFilesDir";
|
||||
this.eventHub = new EventHubClass();
|
||||
this.createBundleContext = function (...args) {
|
||||
console.warn("Context.createBundleContext interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
return new ContextClass();
|
||||
};
|
||||
this.getApplicationContext = function () {
|
||||
console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
return new ContextClass();
|
||||
};
|
||||
this.switchArea = function (...args) {
|
||||
console.warn("Context.switchArea interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
};
|
||||
}
|
||||
}
|
||||
export function mockServiceExtAbility() {
|
||||
const HapModuleInfoMock = {
|
||||
name: '[PC preview] unknow name',
|
||||
description: '[PC preview] unknow description',
|
||||
@@ -55,43 +110,6 @@ export function mockServiceExtAbility() {
|
||||
installationFree: '[PC preview] unknow installationFree',
|
||||
mainElementName: '[PC preview] unknow mainElementName',
|
||||
}
|
||||
const BaseContextClass = class BaseContext {
|
||||
constructor() {
|
||||
console.warn('BaseContext.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.stageMode = "[PC Preview] unknow stageMode";
|
||||
}
|
||||
}
|
||||
const ContextClass = class Context extends BaseContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
console.warn('Context.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.applicationInfo = ApplicationInfoMock;
|
||||
this.cacheDir = "[PC Preview] unknow cacheDir";
|
||||
this.tempDir = "[PC Preview] unknow tempDir";
|
||||
this.filesDir = "[PC Preview] unknow filesDir";
|
||||
this.databaseDir = "[PC Preview] unknow databaseDir";
|
||||
this.storageDir = "[PC Preview] unknow storageDir";
|
||||
this.bundleCodeDir = "[PC Preview] unknow bundleCodeDir";
|
||||
this.distributedFilesDir = "[PC Preview] unknow distributedFilesDir";
|
||||
this.eventHub = "[PC Preview] unknow eventHub";
|
||||
this.createBundleContext = function (...args) {
|
||||
console.warn("Context.createBundleContext interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
return new ContextClass();
|
||||
};
|
||||
this.getApplicationContext = function () {
|
||||
console.warn("Context.getApplicationContext interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
return new ContextClass();
|
||||
};
|
||||
this.switchArea = function (...args) {
|
||||
console.warn("Context.switchArea interface mocked in the Previewer. How this interface works on the Previewer" +
|
||||
" may be different from that on a real device.")
|
||||
};
|
||||
}
|
||||
}
|
||||
const ExtAbilityContextClass = class ExtAbilityContext extends ContextClass {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 mockUriPermissionManager() {
|
||||
const UriPermissionManagerClass = class UriPermissionManager {
|
||||
constructor() {
|
||||
console.warn('application.UriPermissionManager.constructor interface mocked in the Previewer. How this interface works on' +
|
||||
' the Previewer may be different from that on a real device.');
|
||||
this.verifyUriPermission = function (...args) {
|
||||
console.warn("UriPermissionManager.verifyUriPermission 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.paramNumberMock);
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(paramMock.paramNumberMock);
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return new UriPermissionManagerClass();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import { mockAppManager } from './applicationAppManager'
|
||||
import { mockDataShareExtensionAbility } from './applicationDataShareExtensionAbility'
|
||||
import { mockMissionManager } from "./applicationMissionManager"
|
||||
import { mockServiceExtAbility } from "./applicationServiceExtAbility"
|
||||
import { mockUriPermissionManager } from "./applicationUriPermissionManager"
|
||||
import { mockCommonEvent } from './commonEvent'
|
||||
import { mockNotification } from './notification'
|
||||
import { mockFileio } from './fileio'
|
||||
@@ -100,6 +101,8 @@ export function mockRequireNapiFun() {
|
||||
return mockMissionManager();
|
||||
case "application.ServiceExtAbility":
|
||||
return mockServiceExtAbility();
|
||||
case "application.UriPermissionManager":
|
||||
return mockUriPermissionManager();
|
||||
case "commonEvent":
|
||||
return mockCommonEvent();
|
||||
case "notification":
|
||||
|
||||
Reference in New Issue
Block a user