!377 新增元能力api mock

Merge pull request !377 from liuyanzhi2020/liu0706
This commit is contained in:
openharmony_ci
2022-07-11 01:32:21 +00:00
committed by Gitee
12 changed files with 454 additions and 91 deletions
+1 -25
View File
@@ -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) {
@@ -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()
@@ -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();
})
}
}
}
@@ -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",
}
@@ -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",
}
+10 -1
View File
@@ -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'
@@ -267,12 +270,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":
@@ -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;
}
@@ -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();
}
@@ -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,
}
@@ -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();
}
@@ -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";
}
}
@@ -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
}