未验证 提交 91e043b2 编写于 作者: O openharmony_ci 提交者: Gitee

!2629 add appexecfwk actsbundlemanageretstest

Merge pull request !2629 from dy/OpenHarmony-3.1-Release
......@@ -25,6 +25,7 @@ group("bundlemanager") {
"actsbmskittest:ActsBmsKitTest",
"actsbmsmetadatatest:ActsBmsMetaDataTest",
"actsbmsmoduleusagerecordtest:ActsBmsModuleUsageRecordTest",
"actsbundlemanageretstest:ActsBundleManagerEtsTest",
"actsbundlemanagertest:ActsBundleManagerTest",
"actsbundlemanageruninstall:ActsBundleManagerUninstallTest",
"actsbundlemgrmultipleinstalltest:ActsBundleMgrMultipleInstallTest",
......
......@@ -15,7 +15,7 @@
import bundle from '@ohos.bundle'
import innerBundleManager from '@ohos.bundle.innerBundleManager'
import { describe, it, expect } from 'deccjsunit/index'
import {describe, it, expect} from 'deccjsunit/index'
const STATUS_INSTALL_PERMISSION_DENIED = 0X44;
const STATUS_UNINSTALL_PERMISSION_DENIED = 0X45;
......@@ -47,7 +47,7 @@ describe('ActsBmsJsUnPermissionTest', function () {
expect(data.status).assertEqual(STATUS_INSTALL_PERMISSION_DENIED);
expect(data.statusMessage).assertEqual("STATUS_INSTALL_PERMISSION_DENIED");
done();
};
}
});
/*
......@@ -69,7 +69,7 @@ describe('ActsBmsJsUnPermissionTest', function () {
expect(data.status).assertEqual(STATUS_UNINSTALL_PERMISSION_DENIED);
expect(data.statusMessage).assertEqual("STATUS_UNINSTALL_PERMISSION_DENIED");
done();
};
}
});
/*
......@@ -144,8 +144,8 @@ describe('ActsBmsJsUnPermissionTest', function () {
it('queryAbilityByWantTest_100', 0, async function (done) {
console.debug('queryAbilityByWantTest_100 start');
bundle.queryAbilityByWant({
bundleName : LAUNCHER_BUNDLE_NAME,
abilityName : LAUNCHER_MAIN_ABILITY
bundleName: LAUNCHER_BUNDLE_NAME,
abilityName: LAUNCHER_MAIN_ABILITY
}, DEFAULT_FLAG, DEFAULT_USER_ID).then(data => {
expect().assertFail();
done();
......@@ -195,8 +195,8 @@ describe('ActsBmsJsUnPermissionTest', function () {
it('setAbilityEnabledTest_100', 0, async function (done) {
console.debug('setAbilityEnabledTest_100 start');
let abilityInfo = {
bundleName : LAUNCHER_BUNDLE_NAME,
name : LAUNCHER_MAIN_ABILITY
bundleName: LAUNCHER_BUNDLE_NAME,
name: LAUNCHER_MAIN_ABILITY
};
bundle.setAbilityEnabled(abilityInfo, false).then(data => {
expect().assertFail();
......@@ -254,4 +254,40 @@ describe('ActsBmsJsUnPermissionTest', function () {
done();
});
});
/*
* @tc.number: getAbilityLabelTest_100
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('getAbilityLabelTest_100', 0, async function (done) {
console.debug('[getAbilityLabelTest_100] promise START');
await bundle.getAbilityLabel(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY)
.then((data) => {
expect().assertFail();
done();
})
.catch((error) => {
expect(error).assertEqual(INVALID_CODE);
done();
});
});
/*
* @tc.number: getAbilityInfo_100
* @tc.name: test getAbilityInfo
* @tc.desc: test getAbilityInfo
*/
it('getAbilityInfo_100', 0, async function (done) {
console.debug('getAbilityInfo_100 start');
bundle.getAbilityInfo(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY).then(data => {
expect().assertFail();
done();
}).catch(err => {
expect(err).assertEqual(INVALID_CODE);
done();
});
})
})
# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsBundleManagerEtsTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_ets_assets",
":hjs_demo_ets_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsBundleManagerEtsTest"
}
ohos_js_assets("hjs_demo_ets_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("hjs_demo_ets_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for actsbundleetsgetinfotest Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"package": "com.open.harmony.packagemag",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsBundleManagerEtsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.open.harmony.packagemag",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.open.harmony.packagemag",
"name": ".MyApplication",
"mainAbility": "com.open.harmony.packagemag.MainAbility",
"deviceType": [
"phone"
],
"reqPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.CHANGE_ABILITY_ENABLED_STATE"
}
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:mainability_description",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"srcPath": "ServiceAbility",
"name": ".ServiceAbility",
"icon": "$media:icon",
"srcLanguage": "ets",
"description": "$string:description_serviceability",
"type": "service"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/second"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 default {
onCreate() {
console.info('Application onCreate')
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 router from '@system.router';
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets";
import testsuite from "../test/List.test.ets";
import featureAbility from "@ohos.ability.featureAbility";
async function routePage() {
let options = {
uri: 'pages/second'
}
try {
await router.push(options)
} catch (err) {
console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`)
}
}
@Entry
@Component
struct Index {
aboutToAppear() {
console.info("start run testcase!!!!")
featureAbility.getWant()
.then((Want) => {
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
core.addService('expect', expectExtend);
const reportExtend = new ReportExtend(file);
core.addService('report', reportExtend);
core.init();
core.subscribeEvent('task', reportExtend);
const configService = core.getDefaultService('config');
console.info('parameters---->' + JSON.stringify(Want.parameters));
configService.setConfig(Want.parameters);
testsuite();
core.execute();
console.info('Operation successful. Data: ' + JSON.stringify(Want));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('ACE ETS TEST 包管理 2 ')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
routePage()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag'
const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility'
const SERVICE_ABILITY_NAME = 'com.open.harmony.packagemag.ServiceAbility'
const OTHER_BUNDLE_NAME = 'com.ohos.acepackage'
const OTHER_ABILITY_NAME = 'com.ohos.acepackage.MainAbility'
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'
const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'
export default function getAbilityLabelJsUnit() {
describe('context_getAbilityLabel_test', function () {
/*
* @tc.number: context_getAbilityLabel_test_0100
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0100', 0, async function (done) {
let mData;
var timeOldStamp = await Utils.getNowTime();
await Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0100]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_getAbilityLabel_test_0100] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_getAbilityLabel_test_0100] promise error is: ' + error);
expect(error).assertFail();
});
getAbilityLabelSuccess('[context_getAbilityLabel_test_0100]', mData);
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0200
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callbac)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0200', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME, (error, data) => {
if(error){
console.error('[context_getAbilityLabel_test_0200]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_getAbilityLabel_test_0200] callBack error: ' + error);
console.info('[context_getAbilityLabel_test_0200] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityLabelSuccess('[context_getAbilityLabel_test_0200]', mData);
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0300
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0300', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mError;
await Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp);
console.info('[context_getAbilityLabel_test_0300] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
var timeNewStamp = Utils.getNowTime();
mError = error;
Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp);
console.info('[context_getAbilityLabel_test_0300] promise error is: ' + error);
expect(mError).assertEqual(1);
});
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0300]', mError);
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0400
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0400', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mError;
Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR, (error, data) => {
if(error !== null){
console.info('[context_getAbilityLabel_test_0400] callBack error: ' + error);
expect(error).assertEqual(1);
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp);
mError = error;
console.info('[context_getAbilityLabel_test_0400] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0400]', mError);
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0500
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0500', 0, async function (done) {
let mData;
let mError = null;
var timeOldStamp = await Utils.getNowTime();
await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0500]', timeOldStamp, timeNewStamp);
mData = data;
expect(mData).assertFail();
console.info('[context_getAbilityLabel_test_0500] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
mError = error;
console.info('[context_getAbilityLabel_test_0500] promise error is: ' + error);
getAbilityLabelFailure('[context_getAbilityLabel_test_0500]', mError);
});
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0600
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0600', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME, (error, data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0600]', timeOldStamp, timeNewStamp);
console.info('[context_getAbilityLabel_test_0600] callBack error: ' + error);
getAbilityLabelFailure('[context_getAbilityLabel_test_0600]', error);
expect(data).assertEqual(undefined);
});
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0700
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0700', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mError;
Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME, (error, data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0700]', timeOldStamp, timeNewStamp);
mError = error;
if(mError !== null){
console.info('[context_getAbilityLabel_test_0600] callBack error: ' + error);
}
console.info('[context_getAbilityLabel_test_0700] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0700]', mError);
done();
});
function getAbilityLabelSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
console.log(msg + ' result ' + data);
expect(typeof (data)).assertEqual('string');
expect(data).assertEqual("entry_MainAbility");
}
function getAbilityLabelFailure(msg, error) {
console.log(msg + ' Failure ');
console.log(msg + ' error ' + JSON.stringify(error));
expect(typeof (error)).assertEqual('number');
expect(error).assertEqual(1)
}
})
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import bundleManager from '@ohos.bundle';
export default function GetabilityInfo() {
describe('GetabilityInfo', function () {
let bundleName = "com.open.harmony.packagemag";
let abilityName = "com.open.harmony.packagemag.MainAbility";
let bundleName_other = "com.ohos.acecollaboration";
let abilityName_other = "com.ohos.acecollaboration.MainAbility";
let bundleName1 = "com.harmony.packagemag";
let abilityName1 = "com.harmony.packagemag1.MainAbility";
/*
* @tc.number: bundle_GetabilityInfo_test_0100
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('bundle_GetabilityInfo_test_0100', 0, async function (done) {
let mData;
var timeOldStamp = await Utils.getNowTime();
await bundleManager.getAbilityInfo(bundleName, abilityName)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('bundle_GetabilityInfo_test_0100', timeOldStamp, timeNewStamp)
console.info('[bundle_GetabilityInfo_test_0100] getApplicationInfo promise data is: ' + JSON.stringify(data));
expect(typeof (data)).assertEqual("object");
mData = data;
}).catch((error) => {
console.error('[bundle_GetabilityInfo_test_0100]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
})
checkAbilityInfo(mData);
done();
});
/*
* @tc.number: bundle_GetabilityInfo_test_0200
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('bundle_GetabilityInfo_test_0200', 0, async function (done) {
let mData;
var timeOldStamp = await Utils.getNowTime();
await bundleManager.getAbilityInfo(bundleName, abilityName, (err, data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('bundle_GetabilityInfo_test_0200', timeOldStamp, timeNewStamp)
if (err) {
console.error('[bundle_GetabilityInfo_test_0200]Operation failed. Cause: ' + JSON.stringify(err));
expect(err).assertFail();
}
console.info('[bundle_GetabilityInfo_test_0200] getApplicationInfo callback data is: ' + JSON.stringify(data));
mData = data;
})
await Utils.sleep(2000);
checkAbilityInfo(mData);
done();
});
/*
* @tc.number: bundle_GetabilityInfo_test_0300
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('bundle_GetabilityInfo_test_0300', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
await bundleManager.getAbilityInfo(bundleName_other, abilityName_other)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('bundle_GetabilityInfo_test_0300',timeOldStamp,timeNewStamp)
expect(data).assertFail();
}).catch((error) => {
console.error('[bundle_GetabilityInfo_test_0300]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertEqual(1);
});
done();
});
/*
* @tc.number: bundle_GetabilityInfo_test_0400
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('bundle_GetabilityInfo_test_0400', 0, async function (done) {
let error1;
var timeOldStamp = await Utils.getNowTime();
bundleManager.getAbilityInfo(bundleName1, abilityName)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('bundle_GetabilityInfo_test_0400', timeOldStamp, timeNewStamp)
console.info('[bundle_GetabilityInfo_test_0400] getApplicationInfo data is: ' + JSON.stringify(data));
expect(typeof (data)).assertEqual("object");
}).catch((error) => {
console.error('[bundle_GetabilityInfo_test_0400]Operation failed. Cause: ' + JSON.stringify(error));
error1 = error;
})
await Utils.sleep(1000);
await expect(error1).assertEqual(1);
done();
});
/*
* @tc.number: bundle_GetabilityInfo_test_0500
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('bundle_GetabilityInfo_test_0500', 0, async function (done) {
let error
await bundleManager.getAbilityInfo(bundleName, abilityName1).then((data) => {
console.info('[bundle_GetabilityInfo_test_0500] START' + JSON.stringify(data));
}).catch((err) => {
console.info('[bundle_GetabilityInfo_test_0500] err = ' + JSON.stringify(err));
error = err
})
expect(error).assertEqual(1);
done();
console.info('[bundle_GetabilityInfo_test_0500] END');
});
/*
* @tc.number: bundle_GetabilityInfo_test_0600
* @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
let bundleName2 = "";
it('bundle_GetabilityInfo_test_0600', 0, async function (done) {
let error1;
var timeOldStamp = await Utils.getNowTime();
bundleManager.getAbilityInfo(bundleName2, abilityName)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('bundle_GetabilityInfo_test_0600', timeOldStamp, timeNewStamp)
console.info('[bundle_GetabilityInfo_test_0600] getApplicationInfo data promise is: ' + JSON.stringify(data));
expect(typeof (data)).assertEqual("object");
}).catch((error) => {
console.error('[bundle_GetabilityInfo_test_0600]Operation failed. Cause: ' + JSON.stringify(error));
error1 = error;
})
await Utils.sleep(1000);
await expect(error1).assertEqual(1);
done();
});
/**
* 打印AbilityInfo属性信息
* @param data
*/
function checkAbilityInfo(data) {
expect(typeof (data.bundleName)).assertEqual("string");
expect(data.bundleName).assertEqual("com.open.harmony.packagemag")
expect(typeof (data.name)).assertEqual("string");
expect(data.name).assertEqual("com.open.harmony.packagemag.MainAbility");
expect(data.label).assertEqual("$string:entry_MainAbility");
expect(typeof (data.label)).assertEqual("string");
expect(data.description).assertEqual("$string:mainability_description");
expect(typeof (data.description)).assertEqual("string");
expect(data.icon).assertEqual("$media:icon");
expect(typeof (data.icon)).assertEqual("string");
expect(data.srcPath).assertEqual("MainAbility");
expect(typeof (data.srcPath)).assertEqual("string");
expect(data.srcLanguage).assertEqual("ets");
expect(typeof (data.srcLanguage)).assertEqual("string");
expect(data.isVisible).assertEqual(true);
expect(Array.isArray(data.permissions)).assertEqual(true);
expect(Array.isArray(data.deviceCapabilities)).assertEqual(true);
expect(data.deviceTypes[0]).assertEqual("phone");
expect(typeof (data.process)).assertEqual("string");
expect(data.process).assertEqual("");
expect(typeof (data.uri)).assertEqual("string");
expect(data.uri).assertEqual("");
expect(data.moduleName).assertEqual("entry");
expect(typeof (data.moduleName)).assertEqual("string");
expect(typeof (data.applicationInfo)).assertEqual("object");
checkApplicationInfo(data.applicationInfo);
console.log("---checkAbilityInfo End--- ");
}
/**
* 打印ApplicationInfo属性信息
* @param data
*/
function checkApplicationInfo(info) {
expect(typeof (info)).assertEqual("object")
expect(typeof (info.name)).assertEqual("string")
expect(info.name).assertEqual("com.open.harmony.packagemag");
expect(typeof (info.codePath)).assertEqual("string")
expect(info.codePath).assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag");
expect(typeof (info.accessTokenId)).assertEqual("number")
expect(info.accessTokenId > 0).assertTrue()
expect(typeof (info.description)).assertEqual("string")
expect(info.description).assertEqual("$string:mainability_description")
expect(typeof (info.descriptionId)).assertEqual("number")
expect(info.descriptionId > 0).assertTrue()
expect(typeof (info.icon)).assertEqual("string")
expect(info.icon).assertEqual("$media:icon")
expect(typeof (info.iconId)).assertEqual("number")
expect(info.iconId > 0).assertTrue()
expect(typeof (info.label)).assertEqual("string")
expect(info.label).assertEqual("$string:entry_MainAbility")
expect(typeof (info.labelId)).assertEqual("number")
expect(info.labelId > 0).assertTrue()
expect(info.systemApp).assertEqual(true)
expect(typeof (info.entryDir)).assertEqual("string")
expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag/com.open.harmony.packagemag");
expect(typeof (info.supportedModes)).assertEqual("number")
expect(info.supportedModes).assertEqual(0)
expect(typeof (info.process)).assertEqual("string")
expect(info.process).assertEqual("")
expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true);
expect(info.moduleSourceDirs[0]).assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag/com.open.harmony.packagemag");
expect(Array.isArray(info.permissions)).assertEqual(true);
}
/**
* 打印ApplicationInfo属性信息
* @param data
*/
function checkAbilityInfo_other(data) {
expect(typeof (data.bundleName)).assertEqual("string");
expect(data.bundleName).assertEqual("com.ohos.acecollaboration");
expect(typeof (data.name)).assertEqual("string");
expect(data.name).assertEqual("com.ohos.acecollaboration.MainAbility");
expect(data.label).assertEqual("$string:entry_MainAbility");
expect(typeof (data.label)).assertEqual("string");
expect(data.description).assertEqual("$string:mainability_description");
expect(typeof (data.description)).assertEqual("string");
expect(data.icon).assertEqual("$media:icon");
expect(typeof (data.icon)).assertEqual("string");
expect(data.srcPath).assertEqual("MainAbility");
expect(typeof (data.srcPath)).assertEqual("string");
expect(data.srcLanguage).assertEqual("ets");
expect(typeof (data.srcLanguage)).assertEqual("string");
expect(data.isVisible).assertEqual(true);
expect(Array.isArray(data.permissions)).assertEqual(true);
expect(Array.isArray(data.deviceCapabilities)).assertEqual(true);
expect(data.deviceTypes[0]).assertEqual("phone");
expect(typeof (data.process)).assertEqual("string");
expect(data.process).assertEqual("");
expect(typeof (data.uri)).assertEqual("string");
expect(data.uri).assertEqual("");
expect(data.moduleName).assertEqual("entry");
expect(typeof (data.moduleName)).assertEqual("string");
expect(typeof (data.applicationInfo)).assertEqual("object");
checkApplicationInfo_other(data.applicationInfo);
console.log("---checkAbilityInfo_other End--- ");
}
/**
* 打印ApplicationInfo属性信息
* @param data
*/
function checkApplicationInfo_other(info) {
expect(typeof (info)).assertEqual("object")
expect(typeof (info.name)).assertEqual("string")
expect(info.name).assertEqual("com.ohos.acecollaboration");
expect(typeof (info.codePath)).assertEqual("string")
expect(info.codePath).assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration");
expect(typeof (info.accessTokenId)).assertEqual("number")
expect(info.accessTokenId > 0).assertTrue()
expect(typeof (info.description)).assertEqual("string")
expect(info.description).assertEqual("$string:mainability_description")
expect(typeof (info.descriptionId)).assertEqual("number")
expect(info.descriptionId > 0).assertTrue()
expect(typeof (info.icon)).assertEqual("string")
expect(info.icon).assertEqual("$media:icon")
expect(typeof (info.iconId)).assertEqual("number")
expect(info.iconId > 0).assertTrue()
expect(typeof (info.label)).assertEqual("string")
expect(info.label).assertEqual("$string:entry_MainAbility")
expect(typeof (info.labelId)).assertEqual("number")
expect(info.labelId > 0).assertTrue()
expect(info.systemApp).assertEqual(true)
expect(typeof (info.entryDir)).assertEqual("string")
expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration/com.ohos.acecollaboration");
expect(typeof (info.supportedModes)).assertEqual("number")
expect(info.supportedModes).assertEqual(0)
expect(typeof (info.process)).assertEqual("string")
expect(info.process).assertEqual("")
expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true);
expect(info.moduleSourceDirs[0]).assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration/com.ohos.acecollaboration");
expect(Array.isArray(info.permissions)).assertEqual(true);
}
});
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag'
const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility'
const ABILITY = {
bundleName: BUNDLE_NAME,
name: ABILITY_NAME
}
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'
const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'
const ABILITY_ERROR = {
bundleName: BUNDLE_NAME_ERROR,
name: ABILITY_NAME_ERROR
}
export default function isAbilityEnabledETSUnit() {
describe('context_isAbilityEnabled_test', function () {
/*
* @tc.number: context_isAbilityEnabled_test_0100
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0100', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isAbilityEnabled(ABILITY)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0100] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_isAbilityEnabled_test_0100] promise error is: ' + error);
expect(error).assertFail();
});
getAbilityEnabledSuccess('[context_isAbilityEnabled_test_0100]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0200
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0200', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isAbilityEnabled(ABILITY, (error, data) => {
if(error){
console.error('[context_isAbilityEnabled_test_0200]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0200]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0200] callBack error: ' + error);
console.info('[context_isAbilityEnabled_test_0200] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityEnabledSuccess('[context_isAbilityEnabled_test_0200]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0300
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0300', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isAbilityEnabled(ABILITY_ERROR)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0300] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp);
console.info('[context_isAbilityEnabled_test_0300] promise error is: ' + error);
expect(error).assertFail();
});
getAbilityEnabledFalse('[context_isAbilityEnabled_test_0300]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0400
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0400', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isAbilityEnabled(ABILITY_ERROR, (error, data) => {
if(error){
console.error('[context_isAbilityEnabled_test_0400]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0400] callBack error: ' + error);
console.info('[context_isAbilityEnabled_test_0400] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
console.info('[context_isAbilityEnabled_test_0400] Failure ');
getAbilityEnabledFalse('[context_isAbilityEnabled_test_0300]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0500
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0500', 0, async function (done) {
await Bundle.setAbilityEnabled(ABILITY, true)
.then((data) => {
console.info('[context_isAbilityEnabled_test_0500] set enable true data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isAbilityEnabled_test_0500] set enable true error is: ' + error);
expect(error).assertFail();
})
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isAbilityEnabled(ABILITY)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0500]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0500] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_isAbilityEnabled_test_0500] promise error is: ' + error);
expect(error).assertFail();
});
getAbilityEnabledTrue('[context_isAbilityEnabled_test_0500]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0600
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0600', 0, async function (done) {
await Bundle.setAbilityEnabled(ABILITY, false)
.then((data) => {
console.info('[context_isAbilityEnabled_test_0600] set enable false data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isAbilityEnabled_test_0600] set enable false error is: ' + error);
expect(error).assertFail();
})
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isAbilityEnabled(ABILITY)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0600]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0600] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_isAbilityEnabled_test_0600] promise error is: ' + error);
expect(error).assertFail();
});
getAbilityEnabledFalse('[context_isAbilityEnabled_test_0600]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0700
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0700', 0, async function (done) {
await Bundle.setAbilityEnabled(ABILITY, true)
.then((data) => {
console.info('[context_isAbilityEnabled_test_0700] set enable true data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isAbilityEnabled_test_0700] set enable true error is: ' + error);
expect(error).assertFail();
})
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isAbilityEnabled(ABILITY, (error, data) => {
if(error){
console.error('[context_isAbilityEnabled_test_0700]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0700]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0700] callBack error: ' + error);
console.info('[context_isAbilityEnabled_test_0700] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityEnabledTrue('[context_isAbilityEnabled_test_0700]', mData);
done();
});
/*
* @tc.number: context_isAbilityEnabled_test_0800
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isAbilityEnabled_test_0800', 0, async function (done) {
await Bundle.setAbilityEnabled(ABILITY, false)
.then((data) => {
console.info('[context_isAbilityEnabled_test_0800] set enable false data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isAbilityEnabled_test_0800] set enable false error is: ' + error);
expect(error).assertFail();
})
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isAbilityEnabled(ABILITY, (error, data) => {
if(error){
console.error('[context_isAbilityEnabled_test_0800]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isAbilityEnabled_test_0800]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isAbilityEnabled_test_0800] callBack error: ' + error);
console.info('[context_isAbilityEnabled_test_0800] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getAbilityEnabledFalse('[context_isAbilityEnabled_test_0800]', mData);
done();
});
function getAbilityEnabledSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
console.log(msg + ' data : ' + data);
expect(typeof (data)).assertEqual('boolean')
}
function getAbilityEnabledTrue(msg, data) {
getAbilityEnabledSuccess(msg, data);
expect(data).assertEqual(true);
}
function getAbilityEnabledFalse(msg, data) {
getAbilityEnabledSuccess(msg, data);
expect(data).assertEqual(false);
}
})
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag'
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'
export default function IsApplicationEnabledETSUnit() {
describe('context_isApplicationEnabled_test', function () {
/*
* @tc.number: context_isApplicationEnabled_test_0100
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0100', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isApplicationEnabled(BUNDLE_NAME)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0100]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0100] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_isApplicationEnabled_test_0100] promise error is: ' + error);
expect(error).assertFail();
});
getApplicationEnabledSuccess('[context_isApplicationEnabled_test_0100]', mData);
done();
});
/*
* @tc.number: context_isApplicationEnabled_test_0200
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0200', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => {
if(error){
console.error('[context_isApplicationEnabled_test_0200]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0200]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0200] callBack error: ' + error);
console.info('[context_isApplicationEnabled_test_0200] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getApplicationEnabledSuccess('[context_isApplicationEnabled_test_0200]', mData);
done();
});
/*
* @tc.number: context_isApplicationEnabled_test_0300
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0300', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0300] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp);
console.info('[context_isApplicationEnabled_test_0300] promise error is: ' + error);
expect(error).assertFail();
});
getApplicationEnabledFalse('[context_isApplicationEnabled_test_0300]', mData);
done();
});
/*
* @tc.number: context_isApplicationEnabled_test_0400
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0400', 0, async function (done) {
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR, (error, data) => {
if(error){
console.error('[context_isApplicationEnabled_test_0400]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0400]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0400] callBack error: ' + error);
console.info('[context_isApplicationEnabled_test_0400] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getApplicationEnabledFalse('[context_isApplicationEnabled_test_0300]', mData);
console.info('[context_isApplicationEnabled_test_0400] Failure ');
done();
});
/*
* @tc.number: context_isApplicationEnabled_test_0500
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0500', 0, async function (done) {
await Bundle.setApplicationEnabled(BUNDLE_NAME, true)
.then((data) => {
console.info('[context_isApplicationEnabled_test_0500] set enable true data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isApplicationEnabled_test_0500] set enable true error is: ' + error);
expect(error).assertFail();
});
await Utils.sleep(1000);
var timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isApplicationEnabled(BUNDLE_NAME)
.then((data) => {
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0500]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0500] promise data is: ' + JSON.stringify(data));
})
.catch((error) => {
console.info('[context_isApplicationEnabled_test_0500] promise error is: ' + error);
expect(error).assertFail();
});
getApplicationEnabledTrue('[context_isApplicationEnabled_test_0500]', mData);
done();
});
/*
* @tc.number: context_isApplicationEnabled_test_0600
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_isApplicationEnabled_test_0600', 0, async function (done) {
await Bundle.setApplicationEnabled(BUNDLE_NAME, false)
.then((data) => {
console.info('[context_isApplicationEnabled_test_0600] set enable false data is: ' + JSON.stringify(data));
}).catch((error) => {
console.info('[context_isApplicationEnabled_test_0600] set enable false error is: ' + error);
expect(error).assertFail();
});
await Utils.sleep(1000);
var timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => {
if(error){
console.error('[context_isApplicationEnabled_test_0600]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
var timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0600]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_isApplicationEnabled_test_0600] callBack error: ' + error);
console.info('[context_isApplicationEnabled_test_0600] callBack data is:' + JSON.stringify(data));
});
await Utils.sleep(2000);
getApplicationEnabledFalse('[context_isApplicationEnabled_test_0600]', mData);
done();
});
function getApplicationEnabledSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
console.log(msg + ' data : ' + data);
expect(typeof (data)).assertEqual('boolean')
}
function getApplicationEnabledTrue(msg, data) {
getApplicationEnabledSuccess(msg, data);
expect(data).assertEqual(true);
}
function getApplicationEnabledFalse(msg, data) {
getApplicationEnabledSuccess(msg, data);
expect(data).assertEqual(false);
}
})
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 getabilityInfo from './GetabilityInfo.test.ets';
import getApplicationInfoJsunit from './getApplicationInfoJsunit.test.ets';
import getAllAppInfoJsunit from './getAllApplicationInfoJsunit.test.ets';
import getAbilityLabelJsUnit from "./GetAbilityLabelJsUnit.test.ets";
import isAbilityEnableETSUnit from "./IsAbilityEnabledETSUnit.ets";
import isApplicationEnabledETSUnit from "./IsApplicationEnabledETSUnit.ets";
export default function testsuite() {
//RM.007
getApplicationInfoJsunit();
getAllAppInfoJsunit();
//RM.006
getabilityInfo();
//RM.014
getAbilityLabelJsUnit();
//RM.017
isAbilityEnableETSUnit();
isApplicationEnabledETSUnit();
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2021 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 default class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info(`sleep ${time} over...`)
})
}
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
static async swipe(downX, downY, upX, upY, steps) {
console.info('start to swipe')
this.drags(downX, downY, upX, upY, steps, false)
}
static async drag(downX, downY, upX, upY, steps) {
console.info('start to drag')
this.drags(downX, downY, upX, upY, steps, true)
}
static async drags(downX, downY, upX, upY, steps, drag) {
var xStep;
var yStep;
var swipeSteps;
var ret;
xStep = 0;
yStep = 0;
ret = false;
swipeSteps = steps;
if (swipeSteps == 0) {
swipeSteps = 1;
}
xStep = (upX - downX) / swipeSteps;
yStep = (upY - downY) / swipeSteps;
console.info('move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep)
var downPonit: TouchObject = {
id: 1,
x: downX,
y: downY,
type: TouchType.Down,
}
console.info('down touch started: ' + JSON.stringify(downPonit))
sendTouchEvent(downPonit);
console.info('start to move')
if (drag) {
await this.sleep(500)
}
for (var i = 1;i <= swipeSteps; i++) {
var movePoint: TouchObject = {
id: 1,
x: downX + (xStep * i),
y: downY + (yStep * i),
type: TouchType.Move
}
console.info('move touch started: ' + JSON.stringify(movePoint))
ret = sendTouchEvent(movePoint)
if (ret == false) {
break;
}
await this.sleep(5)
}
console.info('start to up')
if (drag) {
await this.sleep(100)
}
var upPoint: TouchObject = {
id: 1,
x: upX,
y: upY,
type: TouchType.Up,
}
console.info('up touch started: ' + JSON.stringify(upPoint))
sendTouchEvent(upPoint)
await this.sleep(500)
}
static getNowTime() {
return new Date().getTime();
}
static getDurationTime(log,startTime, endTime) {
console.info("Get Interface startTime: " + startTime);
console.info("Get Interface endTime: " + endTime);
var duration = (endTime - startTime);
console.info("Get Interface duration: " + duration);
return duration;
}
}
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import Bundle from '@ohos.bundle';
const TAG_TEST_0100_001 = ' bundle_getAllApplicationInfo_test_0100_001 ';
const TAG_TEST_0100_002 = ' bundle_getAllApplicationInfo_test_0100_002 ';
const TAG_TEST_0100_003 = ' bundle_getAllApplicationInfo_test_0100_003 ';
const TAG_TEST_0200_001 = ' bundle_getAllApplicationInfo_test_0200_004 ';
const TAG_TEST_0200_002 = ' bundle_getAllApplicationInfo_test_0200_005 ';
const TAG_TEST_0200_003 = ' bundle_getAllApplicationInfo_test_0200_006 ';
const TAG_TEST_0300_001 = ' bundle_getAllApplicationInfo_test_0300_007 ';
const TAG_TEST_0400_001 = ' bundle_getAllApplicationInfo_test_0400_008 ';
const TAG_TEST_0500_001 = ' bundle_getAllApplicationInfo_test_0500_009 ';
const TAG_TEST_0500_002 = ' bundle_getAllApplicationInfo_test_0500_0010 ';
const USER_ID_100 = 100;
export default function applicationBundleJsunit() {
describe('appInfoTest', function () {
/**
* @tc.number: bundle_getApplicationInfo_test_0100_001
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_001, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_001 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_001, startTime, endTime);
console.info(TAG_TEST_0100_001 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_001, data)
getApplicationInfoSuccess(TAG_TEST_0100_001, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0100_002
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_ALL_APPLICATION_INFO, USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_002 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_002, startTime, endTime);
console.info(TAG_TEST_0100_002 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_002, data)
getApplicationInfoSuccess(TAG_TEST_0100_002, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0100_003
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_003, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE, USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_003 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_003, startTime, endTime);
console.info(TAG_TEST_0100_003 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_003, data)
getApplicationInfoSuccess(TAG_TEST_0100_003, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_004
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_001, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION)
.catch((error) => {
console.info(TAG_TEST_0200_001 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_001, startTime, endTime);
console.info(TAG_TEST_0200_001 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_001, data)
getApplicationInfoSuccess(TAG_TEST_0200_001, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_005
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_ALL_APPLICATION_INFO)
.catch((error) => {
console.info(TAG_TEST_0200_002 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_002, startTime, endTime);
console.info(TAG_TEST_0200_002 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_002, data)
getApplicationInfoSuccess(TAG_TEST_0200_002, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_006
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_003, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE)
.catch((error) => {
console.info(TAG_TEST_0200_003 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_003, startTime, endTime);
console.info(TAG_TEST_0200_003 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_003, data)
getApplicationInfoSuccess(TAG_TEST_0200_003, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0300_007
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by callBack)
* @tc.level 0
*/
it(TAG_TEST_0300_001, 0, async function (done) {
let datas;
var startTime = await Utils.getNowTime();
Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, USER_ID_100,
(error, data) => {
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0300_001, startTime, endTime);
if(error){
expect(error).assertFail();
console.info(TAG_TEST_0300_001 + 'UserId callBack error: ' + error);
}
console.info(TAG_TEST_0300_001 + 'UserId callBack error: ' + error);
console.info(TAG_TEST_0300_001 + 'UserId callBack data is:' + JSON.stringify(data));
datas = data;
});
await Utils.sleep(2000);
console.info(TAG_TEST_0300_001 + 'UserId callBack datas is:' + JSON.stringify(datas));
expectData(TAG_TEST_0300_001, datas)
getApplicationInfoSuccess(TAG_TEST_0300_001, datas);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0400_008
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by callBack)
* @tc.level 0
*/
it(TAG_TEST_0400_001, 0, async function (done) {
let datas;
var startTime = await Utils.getNowTime();
Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, (error, data) => {
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0400_001, startTime, endTime);
if(error){
expect(error).assertFail();
console.info(TAG_TEST_0400_001 + 'UserId callBack error: ' + error);
}
console.info(TAG_TEST_0400_001 + 'noUserId callBack error: ' + error);
console.info(TAG_TEST_0400_001 + 'noUserId callBack data is:' + JSON.stringify(data));
datas = data;
});
await Utils.sleep(2000);
console.info(TAG_TEST_0400_001 + 'noUserId callBack datas is:' + JSON.stringify(datas));
expectData(TAG_TEST_0400_001, datas)
getApplicationInfoSuccess(TAG_TEST_0400_001, datas);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0500_009
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0500_001, 0, async function (done) {
let errors;
var startTime = await Utils.getNowTime();
await Bundle.getAllApplicationInfo('0')
.then((data) => {
console.info(TAG_TEST_0500_001 + 'noUserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0500_001 + 'noUserId promise error is: ' + error);
errors = error;
expect(errors).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0500_001, startTime, endTime);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0500_0010
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0500_002, 0, async function (done) {
let errors;
var startTime = await Utils.getNowTime();
await Bundle.getAllApplicationInfo('0', USER_ID_100)
.then((data) => {
console.info(TAG_TEST_0500_002 + 'noUserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0500_002 + 'UserId promise error is: ' + error);
errors = error;
expect(errors).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0500_002, startTime, endTime);
done();
});
/**
* expect属性
* @param msg log信息
* @param data 数据源
*/
function expectData(msg, data) {
console.info(msg + 'commonTest data length [' + data.length + ']');
for (var i = 0; i < data.length; i++) {
expect(typeof (data)).assertEqual('object');
expect(typeof (data[i].name)).assertEqual('string');
expect(typeof (data[i].codePath)).assertEqual('string');
expect(typeof (data[i].accessTokenId)).assertEqual('number');
expect(typeof (data[i].description)).assertEqual('string');
expect(typeof (data[i].descriptionId)).assertEqual('number');
expect(typeof (data[i].icon)).assertEqual('string');
expect(typeof (data[i].iconId)).assertEqual('number');
expect(typeof (data[i].label)).assertEqual('string');
expect(typeof (data[i].labelId)).assertEqual('number');
expect(typeof (data[i].systemApp)).assertEqual('boolean')
expect(typeof (data[i].supportedModes)).assertEqual('number');
expect(typeof (data[i].process)).assertEqual('string');
expect(typeof (data[i].entryDir)).assertEqual('string');
expect(typeof (data[i].metaData)).assertEqual('object');
expect(typeof (data[i].metadata)).assertEqual('object');
expect(typeof (data[i].enabled)).assertEqual('boolean');
expect(typeof (data[i].flags)).assertEqual('number');
expect(typeof (data[i].uid)).assertEqual('number');
expect(typeof (data[i].entityType)).assertEqual('string');
expect(typeof (data[i].removable)).assertEqual('boolean');
expect(Array.isArray(data[i].permissions)).assertEqual(true);
expect(Array.isArray(data[i].moduleSourceDirs)).assertEqual(true);
expect(Array.isArray(data[i].moduleInfos)).assertEqual(true);
}
}
/**
* expect指定数据属性值
* @param msg log信息
* @param data 数据源
*/
function getApplicationInfoSuccess(msg, data) {
console.info(msg + 'getApplicationInfoSuccess data length [' + data.length + ']');
for (var i = 0; i < data.length; i++) {
if (data[i].name === 'com.open.harmony.packagemag' || i === 0 && data[i].name === '') {
console.info(msg + JSON.stringify(data[i]));
expect(data[i].name).assertEqual('com.open.harmony.packagemag');
expect(data[i].codePath).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag');
expect(data[i].description).assertEqual('$string:mainability_description');
if (data[i].descriptionId !== 0) {
expect(data[i].descriptionId > 0).assertEqual(true);
}
expect(data[i].icon).assertEqual('$media:icon');
expect(data[i].iconId > 0).assertEqual(true);
expect(data[i].label).assertEqual('$string:entry_MainAbility');
expect(data[i].accessTokenId > 0).assertEqual(true);
if (data[i].label !== 0) {
expect(data[i].labelId > 0).assertEqual(true);
};
if (data[i].uid !== 0) {
expect(data[i].uid > 0).assertEqual(true);
};
expect(data[i].systemApp).assertEqual(true);
expect(data[i].supportedModes).assertEqual(0);
expect(data[i].process).assertEqual("");
expect(data[i].entryDir).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag' +
'/com.open.harmony.packagemag');
expect(data[i].enabled).assertEqual(true);
expect(data[i].flags).assertEqual(0);
expect(data[i].entityType).assertEqual('unspecified');
expect(data[i].removable).assertEqual(true);
expect(data[i].moduleInfos[0].moduleName).assertEqual('entry');
expect(data[i].moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
expect(data[i].moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
}
}
}
});
}
\ No newline at end of file
/**
* Copyright (c) 2021 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 {describe, it, expect} from 'deccjsunit/index.ets';
import Utils from './Utils';
import Bundle from '@ohos.bundle';
const TAG_TEST_0100_001 = ' bundle_getApplicationInfo_test_0100_001 ';
const TAG_TEST_0100_002 = ' bundle_getApplicationInfo_test_0100_002 ';
const TAG_TEST_0100_003 = ' bundle_getApplicationInfo_test_0100_003 ';
const TAG_TEST_0200_001 = ' bundle_getApplicationInfo_test_0200_004 ';
const TAG_TEST_0200_002 = ' bundle_getApplicationInfo_test_0200_005 ';
const TAG_TEST_0200_003 = ' bundle_getApplicationInfo_test_0200_006 ';
const TAG_TEST_0300_001 = ' bundle_getApplicationInfo_test_0300_007 ';
const TAG_TEST_0400_001 = ' bundle_getApplicationInfo_test_0400_008 ';
const TAG_TEST_0500_001 = ' bundle_getApplicationInfo_test_0500_009 ';
const TAG_TEST_0500_002 = ' bundle_getApplicationInfo_test_0500_0010 ';
const TAG_TEST_0600_001 = ' bundle_getApplicationInfo_test_0600_0011 ';
const TAG_TEST_0600_002 = ' bundle_getApplicationInfo_test_0600_0012 ';
const TAG_TEST_0600_003 = ' bundle_getApplicationInfo_test_0600_0013 ';
const BUNDLE_NAME = 'com.open.harmony.packagemag';
const BUNDLE_NAME_OTHER = 'com.ohos.acepackage';
const USER_ID_100 = 100;
export default function applicationBundleJsunit() {
describe('appInfoTest', function () {
/**
* @tc.number: bundle_getApplicationInfo_test_0100_001
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_001, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION,
USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_001 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_001, startTime, endTime);
console.info(TAG_TEST_0100_001 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_001, data);
getApplicationInfoSuccess(TAG_TEST_0100_001, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0100_002
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_ALL_APPLICATION_INFO, USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_002 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_002, startTime, endTime);
console.info(TAG_TEST_0100_002 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_002, data);
getApplicationInfoSuccess_plus(TAG_TEST_0100_002, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0100_003
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0100_003, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE,
USER_ID_100)
.catch((error) => {
console.info(TAG_TEST_0100_003 + 'UserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0100_003, startTime, endTime);
console.info(TAG_TEST_0100_003 + ' UserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0100_003, data);
getApplicationInfoSuccess_plus(TAG_TEST_0100_003, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_004
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_001, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION)
.catch((error) => {
console.info(TAG_TEST_0200_001 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_001, startTime, endTime);
console.info(TAG_TEST_0200_001 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_001, data);
getApplicationInfoSuccess(TAG_TEST_0200_001, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_005
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_ALL_APPLICATION_INFO)
.catch((error) => {
console.info(TAG_TEST_0200_002 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_002, startTime, endTime);
console.info(TAG_TEST_0200_002 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_002, data);
getApplicationInfoSuccess_plus(TAG_TEST_0200_002, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0200_006
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0200_003, 0, async function (done) {
var startTime = await Utils.getNowTime();
let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE)
.catch((error) => {
console.info(TAG_TEST_0200_003 + 'onUserId promise error is: ' + error);
expect(error).assertFail();
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0200_003, startTime, endTime);
console.info(TAG_TEST_0200_003 + ' onUserId promise data is: ' + JSON.stringify(data));
expectData(TAG_TEST_0200_003, data);
getApplicationInfoSuccess_plus(TAG_TEST_0200_003, data);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0300_007
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by callBack)
* @tc.level 0
*/
it(TAG_TEST_0300_001, 0, async function (done) {
let errors;
let datas;
var startTime = await Utils.getNowTime();
Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION,
USER_ID_100, (error, data) => {
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0300_001, startTime, endTime);
errors = error;
if(errors){
expect(errors).assertFail();
console.info(TAG_TEST_0300_001 + 'UserId callBack error: ' + error);
}
console.info(TAG_TEST_0300_001 + 'UserId callBack data is:' + JSON.stringify(data));
datas = data;
});
await Utils.sleep(2000);
console.info(TAG_TEST_0300_001 + 'UserId callBack data is: ' + JSON.stringify(datas));
expectData(TAG_TEST_0300_001, datas);
getApplicationInfoSuccess(TAG_TEST_0300_001, datas);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0400_008
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by callBack)
* @tc.level 0
*/
it(TAG_TEST_0400_001, 0, async function (done) {
let errors;
let datas;
var startTime = await Utils.getNowTime();
Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, (error, data) => {
var endTime = Utils.getNowTime();
errors = error;
if(errors){
expect(errors).assertFail();
console.info(TAG_TEST_0400_001 + 'UserId callBack error: ' + error);
}
Utils.getDurationTime(TAG_TEST_0400_001, startTime, endTime);
console.info(TAG_TEST_0400_001 + 'noUserId callBack data is:' + JSON.stringify(data));
datas = data;
});
await Utils.sleep(2000);
console.info(TAG_TEST_0400_001 + 'noUserId callBack data is: ' + JSON.stringify(datas));
expectData(TAG_TEST_0400_001, datas);
getApplicationInfoSuccess(TAG_TEST_0400_001, datas);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0500_009
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0500_001, 0, async function (done) {
var startTime = await Utils.getNowTime();
await Bundle.getApplicationInfo('', 0)
.then((data) => {
console.info(TAG_TEST_0500_001 + 'noUserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0500_001 + 'noUserId promise error is: ' + error);
expect(error).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0500_001, startTime, endTime);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0500_0010
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0500_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
await Bundle.getApplicationInfo('', '0', USER_ID_100)
.then((data) => {
console.info(TAG_TEST_0500_002 + 'UserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0500_002 + 'UserId promise error is: ' + error);
expect(error).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0500_002, startTime, endTime);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0600_0011
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0600_001, 0, async function (done) {
let errors
var startTime = await Utils.getNowTime();
await Bundle.getApplicationInfo(BUNDLE_NAME_OTHER,
Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION)
.then((data) => {
console.info(TAG_TEST_0600_001 + 'other bundleName noUserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0600_001 + 'other bundleName noUserId promise error is: ' + error);
errors = error
expect(errors).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0600_001, startTime, endTime);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0600_0012
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0600_002, 0, async function (done) {
var startTime = await Utils.getNowTime();
let errors
await Bundle.getApplicationInfo(BUNDLE_NAME_OTHER, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION,
USER_ID_100)
.then((data) => {
console.info(TAG_TEST_0600_002 + 'other bundleName UserId promise data is: ' + data);
expect(data).assertFail();
})
.catch((error) => {
console.info(TAG_TEST_0600_002 + 'other bundleName UserId promise error is: ' + error);
errors = error
expect(errors).assertEqual(1);
});
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0600_002, startTime, endTime);
done();
});
/**
* @tc.number: bundle_getApplicationInfo_test_0500_009
* @tc.name: getApplicationInfo : Obtains based on a given bundle name.
* @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/
it(TAG_TEST_0600_003, 0, async function (done) {
var startTime = await Utils.getNowTime();
await Bundle.getApplicationInfo(BUNDLE_NAME, 0)
.then((data) => {
var endTime = Utils.getNowTime();
Utils.getDurationTime(TAG_TEST_0600_003, startTime, endTime);
console.info(TAG_TEST_0600_003 + 'noUserId promise data is: ' + data);
expect(typeof (data)).assertEqual("object");
expectData(TAG_TEST_0600_003, data);
getApplicationInfoSuccess_plus(TAG_TEST_0600_003, data);
})
.catch((error) => {
console.info(TAG_TEST_0600_003 + 'noUserId promise error is: ' + error);
expect(error).assertFail();
});
done();
});
/**
* expect属性
* @param msg log信息
* @param data 数据源
*/
function expectData(msg, data) {
expect(typeof (data)).assertEqual('object');
expect(typeof (data.name)).assertEqual('string');
expect(typeof (data.codePath)).assertEqual('string');
expect(typeof (data.accessTokenId)).assertEqual('number');
expect(typeof (data.description)).assertEqual('string');
expect(typeof (data.descriptionId)).assertEqual('number');
expect(typeof (data.icon)).assertEqual('string');
expect(typeof (data.iconId)).assertEqual('number');
expect(typeof (data.label)).assertEqual('string');
expect(typeof (data.labelId)).assertEqual('number');
expect(typeof (data.systemApp)).assertEqual('boolean')
expect(typeof (data.supportedModes)).assertEqual('number');
expect(typeof (data.process)).assertEqual('string');
expect(typeof (data.entryDir)).assertEqual('string');
expect(typeof (data.metaData)).assertEqual('object');
expect(typeof (data.metadata)).assertEqual('object');
expect(typeof (data.enabled)).assertEqual('boolean');
expect(typeof (data.flags)).assertEqual('number');
expect(typeof (data.uid)).assertEqual('number');
expect(typeof (data.entityType)).assertEqual('string');
expect(typeof (data.removable)).assertEqual('boolean');
expect(Array.isArray(data.permissions)).assertEqual(true);
expect(Array.isArray(data.moduleSourceDirs)).assertEqual(true);
expect(Array.isArray(data.moduleInfos)).assertEqual(true);
}
/**
* expect属性值
* @param msg log信息
* @param data 数据源
*/
function getApplicationInfoSuccess(msg, data) {
expect(data.name).assertEqual('com.open.harmony.packagemag');
expect(data.codePath).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag');
expect(data.accessTokenId > 0).assertEqual(true);
expect(data.description).assertEqual('$string:mainability_description');
expect(data.descriptionId > 0).assertEqual(true);
expect(data.icon).assertEqual('$media:icon');
expect(data.iconId > 0).assertEqual(true);
expect(data.uid > 0).assertEqual(true);
expect(data.label).assertEqual('$string:entry_MainAbility');
expect(data.labelId > 0).assertEqual(true);
expect(data.systemApp).assertEqual(true);
expect(data.supportedModes).assertEqual(0);
expect(data.flags).assertEqual(0);
expect(data.process).assertEqual("");
expect(data.entryDir).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag' +
'/com.open.harmony.packagemag');
expect(data.enabled).assertEqual(true);
expect(data.entityType).assertEqual('unspecified');
expect(data.removable).assertEqual(true);
expect(data.moduleInfos[0].moduleName).assertEqual('entry');
expect(data.moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
expect(data.moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
expect(data.permissions[0]).assertEqual("ohos.permission.CHANGE_ABILITY_ENABLED_STATE");
expect(data.permissions[1]).assertEqual("ohos.permission.GET_BUNDLE_INFO");
expect(data.permissions[2]).assertEqual("ohos.permission.GET_BUNDLE_INFO_PRIVILEGED");
console.log(msg + ' end ' + JSON.stringify(data));
}
/**
* expect属性值
* @param msg log信息
* @param data 数据源
*/
function getApplicationInfoSuccess_plus(msg, data) {
expect(data.name).assertEqual('com.open.harmony.packagemag');
expect(data.codePath).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag');
expect(data.accessTokenId > 0).assertEqual(true);
expect(data.description).assertEqual('$string:mainability_description');
expect(data.descriptionId > 0).assertEqual(true);
expect(data.icon).assertEqual('$media:icon');
expect(data.iconId > 0).assertEqual(true);
expect(data.uid > 0).assertEqual(true);
expect(data.label).assertEqual('$string:entry_MainAbility');
expect(data.labelId > 0).assertEqual(true);
expect(data.systemApp).assertEqual(true);
expect(data.supportedModes).assertEqual(0);
expect(data.flags).assertEqual(0);
expect(data.process).assertEqual("");
expect(data.entryDir).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag' +
'/com.open.harmony.packagemag');
expect(data.enabled).assertEqual(true);
expect(data.entityType).assertEqual('unspecified');
expect(data.removable).assertEqual(true);
expect(data.moduleInfos[0].moduleName).assertEqual('entry');
expect(data.moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
expect(data.moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' +
'com.open.harmony.packagemag/com.open.harmony.packagemag');
console.log(msg + ' end ' + JSON.stringify(data));
}
});
}
\ No newline at end of file
export default {
onStart() {
console.info('ServiceAbility onStart');
},
onStop() {
console.info('ServiceAbility onStop');
},
onCommand(want, startId) {
console.info('ServiceAbility onCommand');
}
};
\ No newline at end of file
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "description_mainability",
"value": "eTS_Empty Ability"
},
{
"name": "mainability_description",
"value": "eTS_Empty Ability"
},
{
"name": "description_serviceability",
"value": "hap sample empty service"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册