diff --git a/bundlemanager/bundle_standard/bundlemanager/BUILD.gn b/bundlemanager/bundle_standard/bundlemanager/BUILD.gn index f5e002d85f8dd9e225b5e3a6479f01e0277fc320..853b080322743022042f95be1d406f334471310d 100644 --- a/bundlemanager/bundle_standard/bundlemanager/BUILD.gn +++ b/bundlemanager/bundle_standard/bundlemanager/BUILD.gn @@ -17,10 +17,13 @@ group("bundlemanager") { testonly = true if (is_standard_system) { deps = [ + "actsbmsaccesstokentest:ActsBmsAccessTokenTest", "actsbmsetsunpermissiontest:ActsBmsEtsUnPermissionTest", "actsbmsgetinfostest:ActsBmsGetInfosTest", + "actsbmshapmoduletest:ActsBmsHapModuleTest", "actsbmsjstest:ActsBmsJsTest", "actsbmsjsunpermissiontest:ActsBmsJsUnPermissionTest", + "actsbmsmetadatatest:ActsBmsMetaDataTest", "actsbundlemanageretstest:ActsBundleManagerEtsTest", "actsbundlemanagerstagetest:ActsBundleMgrStageEtsTest", "actsbundlemanagertest:ActsBundleManagerTest", diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/BUILD.gn b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5ee120a21f5abfd486437451b62a38a17242833d --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/BUILD.gn @@ -0,0 +1,35 @@ +# 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("ActsBmsAccessTokenTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsBmsAccessTokenTest" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" +} +ohos_js_assets("hjs_demo_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/Test.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..a05e88d36cb4fddb2d0c359244254216d1010ca3 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/Test.json @@ -0,0 +1,52 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "120000", + "shell-timeout": "120000", + "bundle-name": "com.example.actsbmsaccesstokentest", + "package-name": "com.example.actsbmsaccesstokentest" + }, + "kits": [ + { + "test-file-name": [ + "ActsBmsAccessTokenTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/test" + ] + }, + { + "type": "PushKit", + "push": [ + "bmsAccessTokenTest1.hap->/data/test/bmsAccessTokenTest1.hap", + "bmsAccessTokenTest2.hap->/data/test/bmsAccessTokenTest2.hap", + "bmsAccessTokenTest3.hap->/data/test/bmsAccessTokenTest3.hap", + "bmsAccessTokenTest4.hap->/data/test/bmsAccessTokenTest4.hap", + "bmsAccessTokenTest5.hap->/data/test/bmsAccessTokenTest5.hap" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "bm install -p /data/test/bmsAccessTokenTest1.hap", + "bm install -p /data/test/bmsAccessTokenTest4.hap", + "bm install -p /data/test/bmsAccessTokenTest3.hap", + "bm install -p /data/test/bmsAccessTokenTest2.hap", + "bm install -p /data/test/bmsAccessTokenTest5.hap" + ], + "teardown-command": [ + "bm uninstall -n com.example.bmsaccesstoken1", + "bm uninstall -n com.example.bmsaccesstoken2", + "bm uninstall -n com.example.bmsaccesstoken3", + "rm -rf /data/test/" + ] + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/signature/openharmony_sx.p7b b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..3a7eb6dc682f3ce734ec103281c9727559e00085 Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/signature/openharmony_sx.p7b differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/config.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..b18b87fb833e0a361be07db633444891d0354c90 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/config.json @@ -0,0 +1,101 @@ +{ + "app": { + "bundleName": "com.example.actsbmsaccesstokentest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.actsbmsaccesstokentest", + "name": ".entry", + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "need use ohos.permission.GET_BUNDLE_INFO" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..c158442201abb1888ae8fb1d57f150c5ec26c36b --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* + * 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('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..01ad739b27f208ff04f21924695104bd27c59df0 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,24 @@ +/* +* 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. +*/ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f99407c7e17ea547a58e64b3ef573867ebcb6918 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,20 @@ + + +
+ + {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f39b26660f7b3450f0c5076e308d6390fd7523a3 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,33 @@ +/* + * 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. + */ + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: 'Test AccessToken' + }, + onInit() { + this.title = 'Test AccessToken'; + }, + onShow() { + console.info('onReady finish') + }, + onReady() { + }, + onBackPress(){ + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ee271df29e516d1c8929054283e5f2bf5c981c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b21c92c6290ea747bd891e2ab673721afc5521ed --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d94b75c085fa1c16a0b2721609b18c57a7295476 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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 default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/ActsBmsAccessTokenTest.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/ActsBmsAccessTokenTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..876541c79d1188d1dcbf59e77ffca59dd9a15c70 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/ActsBmsAccessTokenTest.test.js @@ -0,0 +1,194 @@ +/* + * 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 bundle from '@ohos.bundle' +import account from '@ohos.account.osAccount' +import { describe,beforeAll, it, expect } from '@ohos/hypium' + +const BUNDLE_NAME1 = 'com.example.bmsaccesstoken1'; +const BUNDLE_NAME2 = 'com.example.bmsaccesstoken2'; +const BUNDLE_NAME3 = 'com.example.bmsaccesstoken3'; +let userId = 0; + +export default function ActsBmsAccessTokenTest() { +describe('ActsBmsAccessTokenTest', function () { + + beforeAll(async function (done) { + await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { + console.info("getOsAccountLocalIdFromProcess userid ==========" + account); + userId = account; + done(); + }).catch(err=>{ + console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); + done(); + }) + }); + + /* + * @tc.number: BMS_SECURITY_INITIALIZE_0004 + * @tc.name: getAccessTokenIdOfEntry + * @tc.desc: get the accessTokenId + */ + it('getAccessTokenIdOfEntry', 0, async function (done) { + await bundle.getApplicationInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId) + .then(applicationInfo => { + console.info('accessTokenId: ' + applicationInfo.accessTokenId); + expect(applicationInfo.name).assertEqual(BUNDLE_NAME1); + expect(applicationInfo.accessTokenId).assertLarger(0); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERYPERMISSION_0001 + * @tc.name: getReqPermissionOfEntry + * @tc.desc: get the reqPermissions and reqPermissionStates + */ + it('getReqPermissionOfEntry', 0, async function (done) { + await bundle.getBundleInfo(BUNDLE_NAME3, bundle.BundleFlag.GET_BUNDLE_WITH_REQUESTED_PERMISSION) + .then(bundleInfo => { + expect(bundleInfo.name).assertEqual(BUNDLE_NAME3); + expect(bundleInfo.reqPermissions.length).assertEqual(3); + expect(bundleInfo.reqPermissions[0]).assertEqual("ohos.permission.ALPHA"); + expect(bundleInfo.reqPermissions[1]).assertEqual("ohos.permission.BETA"); + expect(bundleInfo.reqPermissions[2]).assertEqual("ohos.permission.KEEP_BACKGROUND_RUNNING"); + expect(bundleInfo.reqPermissionStates.length).assertEqual(3); + expect(bundleInfo.reqPermissionStates[0]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[1]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[2]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERYPERMISSION_0008 + * @tc.name: getReqPermissionUpdateEntry + * @tc.desc: get the reqPermissions and reqPermissionStates + */ + it('getReqPermissionUpdateEntry', 0, async function (done) { + await bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_REQUESTED_PERMISSION) + .then(bundleInfo => { + expect(bundleInfo.name).assertEqual(BUNDLE_NAME2); + expect(bundleInfo.reqPermissions.length).assertEqual(5); + expect(bundleInfo.reqPermissions[0]).assertEqual("ohos.permission.ALPHA"); + expect(bundleInfo.reqPermissions[1]).assertEqual("ohos.permission.KEEP_BACKGROUND_RUNNING"); + expect(bundleInfo.reqPermissions[2]).assertEqual("ohos.permission.LOCATION_IN_BACKGROUND"); + expect(bundleInfo.reqPermissions[3]).assertEqual("ohos.permission.USE_BLUETOOTH"); + expect(bundleInfo.reqPermissions[4]).assertEqual("ohos.permission.VIBRATE"); + expect(bundleInfo.reqPermissionStates.length).assertEqual(5); + expect(bundleInfo.reqPermissionStates[0]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[1]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + expect(bundleInfo.reqPermissionStates[2]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[3]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + expect(bundleInfo.reqPermissionStates[4]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERYPERMISSION_0003 + * @tc.name: getReqPermissionUpdateEntryAndFeature + * @tc.desc: get the reqPermissions and reqPermissionStates + */ + it('getReqPermissionUpdateEntryAndFeature', 0, async function (done) { + await bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_REQUESTED_PERMISSION) + .then(bundleInfo => { + expect(bundleInfo.name).assertEqual(BUNDLE_NAME1); + expect(bundleInfo.reqPermissions.length).assertEqual(6); + expect(bundleInfo.reqPermissions[0]).assertEqual("ohos.permission.ALPHA"); + expect(bundleInfo.reqPermissions[1]).assertEqual("ohos.permission.BETA"); + expect(bundleInfo.reqPermissions[2]).assertEqual("ohos.permission.KEEP_BACKGROUND_RUNNING"); + expect(bundleInfo.reqPermissions[3]).assertEqual("ohos.permission.LOCATION_IN_BACKGROUND"); + expect(bundleInfo.reqPermissions[4]).assertEqual("ohos.permission.USE_BLUETOOTH"); + expect(bundleInfo.reqPermissions[5]).assertEqual("ohos.permission.VIBRATE"); + expect(bundleInfo.reqPermissionStates.length).assertEqual(6); + expect(bundleInfo.reqPermissionStates[0]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[1]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[2]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + expect(bundleInfo.reqPermissionStates[3]).assertEqual(bundle.GrantStatus.PERMISSION_DENIED); + expect(bundleInfo.reqPermissionStates[4]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + expect(bundleInfo.reqPermissionStates[5]).assertEqual(bundle.GrantStatus.PERMISSION_GRANTED); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /** + * @tc.number BMS_SECURITY_INITIALIZE_0013 + * @tc.name getAccessTokenIdWithDefault + * @tc.desc Test getBundleInfos interfaces with with a flag + */ + it("getAccessTokenIdWithDefault", 0, async function (done) { + await bundle.getApplicationInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_DEFAULT) + .then((applicationInfo) => { + console.info("getAccessTokenIdWithDefault accessTokenId: " + applicationInfo.accessTokenId); + expect(applicationInfo.name).assertEqual(BUNDLE_NAME1); + expect(applicationInfo.accessTokenId).assertLarger(0); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /** + * @tc.number BMS_SECURITY_INITIALIZE_0014 + * @tc.name getAccessTokenIdWithGetAbilities + * @tc.desc Test getBundleInfos interfaces with a flag + */ + it("getAccessTokenIdWithGetAbilities", 0, async function (done) { + await bundle.getApplicationInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES) + .then((applicationInfo) => { + console.info("getAccessTokenIdWithGetAbilities accessTokenId: " + applicationInfo.accessTokenId); + expect(applicationInfo.name).assertEqual(BUNDLE_NAME1); + expect(applicationInfo.accessTokenId).assertLarger(0); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + + /** + * @tc.number BMS_SECURITY_INITIALIZE_0015 + * @tc.name getAccessTokenIdWithGetPermission + * @tc.desc Test getBundleInfos interfaces with a flag + */ + it("getAccessTokenIdWithGetPermission", 0, async function (done) { + await bundle.getApplicationInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION) + .then((applicationInfo) => { + console.info("getAccessTokenIdWithGetPermission accessTokenId: " + applicationInfo.accessTokenId); + expect(applicationInfo.name).assertEqual(BUNDLE_NAME1); + expect(applicationInfo.accessTokenId).assertLarger(0); + done(); + }).catch((err) => { + expect(err).assertFail(); + done(); + }); + }); + +}); +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/List.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d10892909d138dc259dc781cc8fe3aae3e792384 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/js/test/List.test.js @@ -0,0 +1,19 @@ +/* + * 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 ActsBmsAccessTokenTest from './ActsBmsAccessTokenTest.test.js' +export default function testsuite() { +ActsBmsAccessTokenTest() +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/element/string.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b38f30f14d88438bcf4f9f29de0f91abff4b8c6d --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "actsbmsallshortcutinfotest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/media/icon.png b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmsaccesstokentest/src/main/resources/base/media/icon.png differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsetsunpermissiontest/entry/src/main/ets/test/ActsBmsEtsUnPermissionTest.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsetsunpermissiontest/entry/src/main/ets/test/ActsBmsEtsUnPermissionTest.test.ets index 6221fcebde9d3445331ade83c51e1dcdfbef7ce8..d2f2e553b224e3b19f10abe59fa02c4bac90fc16 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsetsunpermissiontest/entry/src/main/ets/test/ActsBmsEtsUnPermissionTest.test.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsetsunpermissiontest/entry/src/main/ets/test/ActsBmsEtsUnPermissionTest.test.ets @@ -42,6 +42,60 @@ export default function actsBmsJsUnPermissionTest() { }) }); + /** + * @tc.number getApplicationInfos_1300 + * @tc.name getApplicationInfosUnPermission + * @tc.desc test getAllApplicationInfo + */ + it('getApplicationInfosUnPermission', 0, async function (done) { + await bundle.getAllApplicationInfo(DEFAULT_FLAG).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(INVALID_CODE); + }); + bundle.getAllApplicationInfo(DEFAULT_FLAG, (err, data) => { + expect(err.code).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /** + * @tc.number getBundleInfo_2000 + * @tc.name getBundleInfoUnPermission + * @tc.desc test getBundleInfo + */ + it('getBundleInfoUnPermission', 0, async function (done) { + await bundle.getBundleInfo(BUNDLE_NAME_OTHER, DEFAULT_FLAG, { userId: userId }).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err).assertEqual(INVALID_CODE); + }); + bundle.getBundleInfo(BUNDLE_NAME_OTHER, DEFAULT_FLAG, { userId: userId }, (err, data) => { + expect(err).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /** + * @tc.number getApplicationInfo_1800 + * @tc.name getApplicationInfoUnPermission + * @tc.desc test getApplicationInfo + */ + it('getApplicationInfoUnPermission', 0, async function (done) { + await bundle.getApplicationInfo(BUNDLE_NAME_OTHER, DEFAULT_FLAG).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(INVALID_CODE); + }); + bundle.getApplicationInfo(BUNDLE_NAME_OTHER, DEFAULT_FLAG, (err, data) => { + expect(err.code).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + /* * @tc.number: SUB_BMS_HAP_STATUS_0011 * @tc.name: hasInstalledUnPermissionSelf @@ -94,6 +148,23 @@ export default function actsBmsJsUnPermissionTest() { }) }); + /* + * @tc.number: SUB_BMS_APPINFO_GETABILITYICON_0006 + * @tc.name: getAbilityIconUnPermission + * @tc.desc: test getAbilityIcon without permission + */ + it('getAbilityIconUnPermission', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER).then(pixelmap => { + expect(pixelmap).assertFail(); + }).catch(err => { + expect(err).assertEqual(1); + }); + bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER, (err, pixelmap) => { + expect(err).assertEqual(1); + done(); + }); + }); + /* * @tc.number: SUB_BMS_APPINFO_GETABILITYINFO_0008 * @tc.name: getAbilityInfoUnPermissionSelf diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsGetBackGroundModes.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsGetBackGroundModes.test.js new file mode 100644 index 0000000000000000000000000000000000000000..666bc0d7e7c76161194a6c30fa6245bb69d3b860 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsGetBackGroundModes.test.js @@ -0,0 +1,208 @@ +/* + * 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 bundle from '@ohos.bundle' +import account from '@ohos.account.osAccount' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit' + +const BUNDLE_NAME1 = 'com.example.third1'; +const BUNDLE_NAME2 = 'com.example.third2'; +const BUNDLE_NAME4 = 'com.example.third4'; +const BUNDLE_NAME5 = 'com.example.third5'; +const BUNDLE_NAME6 = 'com.example.third6'; +const ABILITIY_NAME1 = "com.example.third5.MainAbilityA"; +const ABILITIY_NAME2 = "com.example.third5.MainAbilityB"; +const ABILITIY_NAME3 = "com.example.third2.MainAbilityA"; +const ABILITIY_NAME4 = "com.example.third4.MainAbility"; +const ABILITIY_NAME5 = "com.example.third1.MainAbilityA"; +const ABILITIY_NAME6 = "com.example.third3.MainAbilityA"; +const NUM_TWO = 2; +const NUM_THREE = 3; +const NUM_FOUR = 4; +const NUM_NINE = 9; +const DATATRANSFER = 1; +const AUDIOPLAYBACK = 2; +const AUDIORECORDING = 4; +const LOCATION = 8; +const BLUETOOTHINTERACTION = 16; +const MULTIDEVICECONNECTION = 32; +const WIFIINTERACTION = 64; +const VOIP = 128; +const TASKKEEPING = 256; +let userId = 0; + +export default function ActsBmsGetBackGroundModes() { +describe('ActsBmsGetBackGroundModes', function () { + + beforeAll(async function (done) { + await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { + console.info("getOsAccountLocalIdFromProcess userid ==========" + account); + userId = account; + done(); + }).catch(err => { + console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); + done(); + }) + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0085 + * @tc.name: getBackgroundModesMultiAbility + * @tc.desc: Get the information of the background modes from multi-ability application + */ + it('getBackgroundModesMultiAbility', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: 'action.system.home', + entities: ['entity.system.home'], + deviceId: '0', + bundleName: BUNDLE_NAME5, + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(NUM_FOUR); + if (dataInfos.length == NUM_FOUR) { + expect(dataInfos[NUM_TWO].name).assertEqual(ABILITIY_NAME1); + expect(dataInfos[NUM_TWO].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | + LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); + expect(dataInfos[NUM_THREE].name).assertEqual(ABILITIY_NAME2); + expect(dataInfos[NUM_THREE].backgroundModes).assertEqual(DATATRANSFER | VOIP); + } + let bundleInfos = await bundle.getAllBundleInfo(bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, userId); + for (let i = 0; i < bundleInfos.length; i++) { + if (bundleInfos[i].name == BUNDLE_NAME5) { + for (let j = 0; j < bundleInfos[i].abilityInfos.length; j++) { + if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME1) { + expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual(DATATRANSFER | + AUDIOPLAYBACK | AUDIORECORDING | LOCATION | BLUETOOTHINTERACTION | + MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); + } else if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME2) { + expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual(DATATRANSFER | VOIP); + } + } + } + } + let data3 = await bundle.getBundleInfo(BUNDLE_NAME5, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(data3.abilityInfos[2].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | + LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); + expect(data3.abilityInfos[3].backgroundModes).assertEqual(DATATRANSFER | VOIP); + done(); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0086 + * @tc.name: getBackgroundModesAllModes + * @tc.desc: Get all background modes information, and each ability of the application + * contains one of the background mode + */ + it('getBackgroundModesAllModes', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: 'action.system.home', + entities: ['entity.system.home'], + deviceId: '0', + bundleName: BUNDLE_NAME6, + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(NUM_NINE); + for (let i = 0, len = dataInfos.length; i < len; i++) { + expect(dataInfos[i].backgroundModes).assertEqual(1 << i); + } + done(); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0087 + * @tc.name: getBackgroundModesInvalidModes + * @tc.desc: Read the backgroundModes information of the app's ability and replace invalid attributes + */ + it('getBackgroundModesInvalidModes', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: 'action.system.home', + entities: ['entity.system.home'], + deviceId: '0', + bundleName: BUNDLE_NAME2, + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(NUM_TWO); + if (dataInfos.length == NUM_TWO) { + expect(dataInfos[1].name).assertEqual(ABILITIY_NAME3) + expect(dataInfos[1].backgroundModes).assertEqual(AUDIOPLAYBACK | AUDIORECORDING | LOCATION + | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) + } + bundle.getAllBundleInfo(bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, userId, (err, bundleInfos) => { + for (let i = 0; i < bundleInfos.length; i++) { + if (bundleInfos[i].name == BUNDLE_NAME2) { + for (let j = 0; j < bundleInfos[i].abilityInfos.length; j++) { + if (bundleInfos[i].abilityInfos[j].name == ABILITIY_NAME3) { + expect(bundleInfos[i].abilityInfos[j].backgroundModes).assertEqual( + AUDIOPLAYBACK | AUDIORECORDING | LOCATION | BLUETOOTHINTERACTION + | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); + } + } + } + } + bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, (err, data3) => { + expect(data3.abilityInfos[1].backgroundModes).assertEqual(AUDIOPLAYBACK | AUDIORECORDING | LOCATION + | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING); + done(); + }); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0088 + * @tc.name: getBackgroundModesNotModes + * @tc.desc: Read the backgroundModes information of the app's ability and replace invalid attributes + */ + it('getBackgroundModesNotModes', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: 'action.system.home', + entities: ['entity.system.home'], + deviceId: '0', + bundleName: BUNDLE_NAME4, + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(1); + if (dataInfos.length == 1) { + expect(dataInfos[0].name).assertEqual(ABILITIY_NAME4) + expect(dataInfos[0].backgroundModes).assertEqual(0) + } + done(); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0089 + * @tc.name: getBackgroundModesMultiHap + * @tc.desc: Get the backgroundModes information of the multi-hap package of the application + */ + it('getBackgroundModesMultiHap', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: 'action.system.home', + entities: ['entity.system.home'], + deviceId: '0', + bundleName: BUNDLE_NAME1, + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(NUM_FOUR); + if (dataInfos.length == NUM_FOUR) { + expect(dataInfos[1].name).assertEqual(ABILITIY_NAME5) + expect(dataInfos[1].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | + LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) + expect(dataInfos[3].name).assertEqual(ABILITIY_NAME6) + expect(dataInfos[3].backgroundModes).assertEqual(DATATRANSFER | AUDIOPLAYBACK | AUDIORECORDING | + LOCATION | BLUETOOTHINTERACTION | MULTIDEVICECONNECTION | WIFIINTERACTION | VOIP | TASKKEEPING) + } + done(); + }); + +})} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsQueryAbilityByWant.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsQueryAbilityByWant.test.js index e20e1bfd98956216339ca2dfafd9c3bc79e8658e..ac0dc46d1140c0e065dc8eef064fe0ea07de7c57 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsQueryAbilityByWant.test.js +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/ActsBmsQueryAbilityByWant.test.js @@ -37,6 +37,35 @@ describe('ActsBmsQueryAbilityByWant', function () { }) }); + /* + * @tc.number: SUB_BMS_APPINFO_QUERYSYS_0008 + * @tc.name: queryAbilityByWantThirdApp + * @tc.desc: 1.queryAbilityByWant callback + * 2.queryAbilityByWant for third app + */ + it('queryAbilityByWantThirdApp', 0, async function (done) { + await bundle.queryAbilityByWant({ + action: ACTION_NAME, + entities: [ENTITY_NAME], + bundleName: BUNDLE_NAME1 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION | bundle.BundleFlag.GET_ABILITY_INFO_SYSTEMAPP_ONLY, + userId).then(data => { + expect(data).assertFail(); + }).catch(err => { + expect(err).assertEqual(1); + }); + bundle.queryAbilityByWant({ + action: ACTION_NAME, + entities: [ENTITY_NAME], + bundleName: BUNDLE_NAME1 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION | bundle.BundleFlag.GET_ABILITY_INFO_SYSTEMAPP_ONLY, + userId, (err, data) => { + expect(err).assertEqual(1); + expect(data).assertEqual("QueryAbilityInfos failed"); + done(); + }); + }); + /* * @tc.number: SUB_BMS_APPINFO_QUERYSYS_0007 * @tc.name: queryAbilityByWantSystemApp @@ -77,6 +106,50 @@ describe('ActsBmsQueryAbilityByWant', function () { }); }); + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0084 + * @tc.name: queryAbilityByWantImplicitByEntities + * @tc.desc: The entities in the parameter want pass in the new field, and use the implicit query to get abilitInfos + */ + it('queryAbilityByWantImplicitByEntities', 0, async function (done) { + let dataInfos = await bundle.queryAbilityByWant({ + action: ACTION_NAME, + entities: ["entity.app.music", + "entity.app.email", + "entity.app.contacts", + "entity.app.maps", + "entity.app.browser", + "entity.app.calendar", + "entity.app.messaging", + "entity.app.files", + "entity.app.gallery"], + deviceId: '0', + bundleName: '', + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(dataInfos.length).assertEqual(1); + cheackAbilityInfos(dataInfos[0]); + bundle.queryAbilityByWant({ + action: ACTION_NAME, + entities: ["entity.app.music", + "entity.app.email", + "entity.app.contacts", + "entity.app.maps", + "entity.app.browser", + "entity.app.calendar", + "entity.app.messaging", + "entity.app.files", + "entity.app.gallery"], + deviceId: '0', + bundleName: '', + abilityName: '' + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId, (err, data) => { + expect(data.length).assertEqual(1); + cheackAbilityInfos(data[0]); + done(); + }); + }); + async function cheackAbilityInfos(data) { expect(data.name).assertEqual(ABILITIY_NAME8); expect(data.label).assertEqual('$string:app_name'); diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/List.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/List.test.js index 08c0dbc318e6b6faf58107d35a49a242045d9e13..b6915efeb3af72e4f1c50cedd5854650c7ef0d7b 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/List.test.js +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsgetinfostest/src/main/js/test/List.test.js @@ -12,7 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import ActsBmsQueryAbilityByWant from './ActsBmsQueryAbilityByWant.test.js' +import ActsBmsGetBackGroundModes from './ActsBmsQueryAbilityByWant.test.js' +import ActsBmsQueryAbilityByWant from './ActsBmsGetBackGroundModes.test.js' export default function testsuite() { +ActsBmsGetBackGroundModes() ActsBmsQueryAbilityByWant() } diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/BUILD.gn b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..78d1752b348fede4ded76cde8747859a82fb5c18 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/BUILD.gn @@ -0,0 +1,35 @@ +# 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("ActsBmsHapModuleTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsBmsHapModuleTest" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" +} +ohos_js_assets("hjs_demo_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/Test.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..a90c35a11d3307e8bab09b3b16fd94c232d3f394 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/Test.json @@ -0,0 +1,52 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "com.example.actsbmshapmoduletest", + "package-name": "com.example.actsbmshapmoduletest" + }, + "kits": [ + { + "test-file-name": [ + "ActsBmsHapModuleTest.hap", + "bmsSystemBundleTest1.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/test" + ] + }, + { + "type": "PushKit", + "push": [ + "bmsMainAbilityFirstScene.hap->/data/test/bmsMainAbilityFirstScene.hap", + "bmsMainAbilitySecondScene.hap->/data/test/bmsMainAbilitySecondScene.hap", + "bmsThirdBundleTest2.hap->/data/test/bmsThirdBundleTest2.hap", + "bmsThirdBundleTest5.hap->/data/test/bmsThirdBundleTest5.hap" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "chmod 644 /data/test/*.hap", + "bm install -p /data/test/bmsMainAbilityFirstScene.hap", + "bm install -p /data/test/bmsMainAbilitySecondScene.hap", + "bm install -p /data/test/bmsThirdBundleTest2.hap", + "bm install -p /data/test/bmsThirdBundleTest5.hap" + ], + "teardown-command": [ + "bm uninstall -n com.example.third2", + "bm uninstall -n com.example.third5", + "bm uninstall -n com.example.bmsmainabilityfirstscene", + "rm -rf /data/test/" + ] + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/signature/openharmony_sx.p7b b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..3a7eb6dc682f3ce734ec103281c9727559e00085 Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/signature/openharmony_sx.p7b differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/config.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..2e7d3a576e1be2971b25898d60166ab91752b0f3 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/config.json @@ -0,0 +1,101 @@ +{ + "app": { + "bundleName": "com.example.actsbmshapmoduletest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.actsbmshapmoduletest", + "name": ".entry", + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "need use ohos.permission.GET_BUNDLE_INFO" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..c158442201abb1888ae8fb1d57f150c5ec26c36b --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* + * 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('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..01ad739b27f208ff04f21924695104bd27c59df0 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,24 @@ +/* +* 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. +*/ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f99407c7e17ea547a58e64b3ef573867ebcb6918 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,20 @@ + + +
+ + {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..fc41e318c5798be5a9c9537092ec07743f816083 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: 'Test HapModuleInfo' + }, + onInit() { + this.title = 'Test HapModuleInfo'; + }, + onShow() { + console.info('onReady finish') + }, + onReady() { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ee271df29e516d1c8929054283e5f2bf5c981c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b21c92c6290ea747bd891e2ab673721afc5521ed --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d94b75c085fa1c16a0b2721609b18c57a7295476 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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 default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/ActsBmsHapModuleTest.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/ActsBmsHapModuleTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ab15b64cc00f0915ab44c52df6c8d2934c78e8ef --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/ActsBmsHapModuleTest.test.js @@ -0,0 +1,211 @@ +/* +* 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 bundle from '@ohos.bundle' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +const BUNDLE_NAME1 = 'com.example.bmsmainabilityfirstscene'; +const BUNDLE_NAME2 = 'com.example.third2'; +const BUNDLE_NAME3 = 'com.example.third5'; +const BUNDLE_NAME5 = 'com.example.system1'; +const FIRSTMAINABILITY = 'com.example.bmsmainabilityfirstscene.MainAbility'; +const SECONDMAINABILITY = 'com.example.bmsmainabilitysecondscene.MainAbility'; +const MODULE_NAME = 'entry'; +const ICON = '$media:icon'; +const ICON_ID = 16777218; +const LABEL = '$string:app_name'; +const LABEL_ID = 16777216; +const DEVICE_TYPES = 'default'; +const FIRST_SCENE_HAP_NAME = 'com.example.bmsmainabilityfirstscene.MyApplication'; +const SECOND_SCENE_HAP_NAME = 'com.example.bmsmainabilitysecondscene.MyApplication'; +const THIRD_TWO_HAP_NAME = 'com.example.third2.MyApplication'; +const THIRD_FIVE_HAP_NAME = 'com.example.third5.BmsThirdBundle5'; +const SYSTEM_ONE_HAP_NAME = 'com.example.system1.BmsSystemBundle1'; + +export default function ActsBmsHapModuleTest() { +describe('ActsBmsHapModuleTest', function () { + + /* + * @tc.number: bms_getHapModuleInfo_0100 + * @tc.name: get hapModuleInfo from one app by getBundleInfo + * @tc.desc: get the module information of the hap with type of entry + */ + it('bms_getHapModuleInfo_0100', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, callback); + async function callback(err, result) { + expect(JSON.stringify(result)).assertEqual(JSON.stringify(dataInfo)); + expect(result.hapModuleInfos.length).assertEqual(2); + if (result.hapModuleInfos.length > 0) { + let hapModuleInfo = result.hapModuleInfos[0]; + expect(hapModuleInfo.name).assertEqual(FIRST_SCENE_HAP_NAME); + expect(hapModuleInfo.moduleName).assertEqual(MODULE_NAME); + expect(hapModuleInfo.description).assertEqual(''); + expect(hapModuleInfo.descriptionId).assertEqual(0); + expect(hapModuleInfo.icon).assertEqual(ICON); + expect(hapModuleInfo.label).assertEqual(LABEL); + expect(hapModuleInfo.labelId).assertEqual(LABEL_ID); + expect(hapModuleInfo.iconId).assertEqual(ICON_ID); + expect(hapModuleInfo.backgroundImg).assertEqual(""); + expect(hapModuleInfo.supportedModes).assertEqual(0); + expect(hapModuleInfo.reqCapabilities.length).assertEqual(0); + expect(hapModuleInfo.deviceTypes[0]).assertEqual(DEVICE_TYPES); + expect(hapModuleInfo.mainAbilityName).assertEqual(FIRSTMAINABILITY); + expect(hapModuleInfo.abilityInfo.length).assertLarger(0); + expect(hapModuleInfo.installationFree).assertEqual(false); + done(); + } + } + }); + + /* + * @tc.number: bms_getHapModuleInfo_0200 + * @tc.name: get hapModuleInfo from two modules by getBundleInfo + * @tc.desc: get the module information of the hap with type of feature + */ + it('bms_getHapModuleInfo_0200', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, async (err, result) => { + expect(JSON.stringify(result)).assertEqual(JSON.stringify(dataInfo)); + expect(result.hapModuleInfos.length).assertEqual(2); + if (result.hapModuleInfos.length == 2) { + let hapModuleInfo = result.hapModuleInfos[0]; + let hapModuleInfo1 = result.hapModuleInfos[1]; + checkHapMoudleInfos(hapModuleInfo); + checkHapMoudleInfos(hapModuleInfo1); + expect(hapModuleInfo.name).assertEqual(FIRST_SCENE_HAP_NAME); + expect(hapModuleInfo1.name).assertEqual(SECOND_SCENE_HAP_NAME); + expect(hapModuleInfo.moduleName).assertEqual(MODULE_NAME); + expect(hapModuleInfo.mainAbilityName).assertEqual(FIRSTMAINABILITY); + expect(hapModuleInfo1.moduleName).assertEqual('bmsmainabilitysecondscene'); + expect(hapModuleInfo1.mainAbilityName).assertEqual(SECONDMAINABILITY); + expect(hapModuleInfo.installationFree).assertEqual(false); + expect(hapModuleInfo1.installationFree).assertEqual(true); + done(); + } + }); + }); + + /* + * @tc.number: bms_getHapModuleInfo_0300 + * @tc.name: get hapModuleInfo one app without mainAbility by getBundleInfo + * @tc.desc: get the module information of the hap without mainAbility + */ + it('bms_getHapModuleInfo_0300', 0, async function (done) { + let result = await bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, (err, data) => { + expect(JSON.stringify(result)).assertEqual(JSON.stringify(data)); + expect(result.hapModuleInfos.length).assertEqual(1); + if (result.hapModuleInfos.length > 0) { + let hapModuleInfo = result.hapModuleInfos[0]; + expect(hapModuleInfo.name).assertEqual(THIRD_TWO_HAP_NAME); + expect(hapModuleInfo.moduleName).assertEqual(MODULE_NAME); + expect(hapModuleInfo.description).assertEqual(''); + expect(hapModuleInfo.descriptionId).assertEqual(0); + expect(hapModuleInfo.icon).assertEqual(''); + expect(hapModuleInfo.label).assertEqual(''); + expect(hapModuleInfo.labelId).assertEqual(0); + expect(hapModuleInfo.iconId).assertEqual(0); + expect(hapModuleInfo.backgroundImg).assertEqual(""); + expect(hapModuleInfo.supportedModes).assertEqual(0); + expect(hapModuleInfo.reqCapabilities.length).assertEqual(0); + expect(hapModuleInfo.deviceTypes[0]).assertEqual(DEVICE_TYPES); + expect(hapModuleInfo.mainAbilityName).assertEqual(""); + expect(hapModuleInfo.abilityInfo.length).assertLarger(0); + expect(hapModuleInfo.installationFree).assertEqual(false); + done(); + } + }); + }); + + /* + * @tc.number: bms_getHapModuleInfo_0400 + * @tc.name: get hapModuleInfo through getBundleInfo, an application that adds mainAbility + * @tc.desc: get the module information of the hap with the added field mainAbility + */ + it('bms_getHapModuleInfo_0400', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME3, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + bundle.getBundleInfo(BUNDLE_NAME3, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, async (err, result) => { + expect(JSON.stringify(result)).assertEqual(JSON.stringify(dataInfo)); + expect(result.hapModuleInfos.length).assertEqual(1); + if (result.hapModuleInfos.length == 1) { + let hapModuleInfo = result.hapModuleInfos[0]; + expect(hapModuleInfo.name).assertEqual(THIRD_FIVE_HAP_NAME); + expect(hapModuleInfo.moduleName).assertEqual(MODULE_NAME); + expect(hapModuleInfo.description).assertEqual(''); + expect(hapModuleInfo.descriptionId).assertEqual(0); + expect(hapModuleInfo.icon).assertEqual(ICON); + expect(hapModuleInfo.label).assertEqual(LABEL); + expect(hapModuleInfo.labelId).assertEqual(LABEL_ID); + expect(hapModuleInfo.iconId).assertEqual(16777219); + expect(hapModuleInfo.backgroundImg).assertEqual(""); + expect(hapModuleInfo.supportedModes).assertEqual(0); + expect(hapModuleInfo.reqCapabilities.length).assertEqual(0); + expect(hapModuleInfo.deviceTypes[0]).assertEqual(DEVICE_TYPES); + expect(hapModuleInfo.mainAbilityName).assertEqual("com.example.third5.AMainAbility"); + expect(hapModuleInfo.abilityInfo.length).assertLarger(0); + expect(hapModuleInfo.installationFree).assertEqual(false); + done(); + } + }); + }); + + /* + * @tc.number: bms_getHapModuleInfo_0600 + * @tc.name: get hapModuleInfo from the system through getBundleInfo + * @tc.desc: get module information of mainAbility system application + */ + it('bms_getHapModuleInfo_0600', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME5, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + bundle.getBundleInfo(BUNDLE_NAME5, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, callback); + function callback(err, data) { + expect(JSON.stringify(data)).assertEqual(JSON.stringify(dataInfo)); + expect(data.hapModuleInfos.length).assertEqual(1); + if (data.hapModuleInfos.length == 1) { + let hapModuleInfo = data.hapModuleInfos[0]; + expect(hapModuleInfo.name).assertEqual(SYSTEM_ONE_HAP_NAME); + expect(hapModuleInfo.moduleName).assertEqual(MODULE_NAME); + expect(hapModuleInfo.description).assertEqual(''); + expect(hapModuleInfo.descriptionId).assertEqual(0); + expect(hapModuleInfo.icon).assertEqual(ICON); + expect(hapModuleInfo.label).assertEqual(LABEL); + expect(hapModuleInfo.labelId).assertEqual(LABEL_ID); + expect(hapModuleInfo.iconId).assertEqual(16777219); + expect(hapModuleInfo.backgroundImg).assertEqual(""); + expect(hapModuleInfo.supportedModes).assertEqual(0); + expect(hapModuleInfo.reqCapabilities.length).assertEqual(0); + expect(hapModuleInfo.deviceTypes[0]).assertEqual(DEVICE_TYPES); + expect(hapModuleInfo.mainAbilityName).assertEqual("com.example.system1.MainAbility"); + expect(hapModuleInfo.abilityInfo.length).assertLarger(0); + expect(hapModuleInfo.installationFree).assertEqual(false); + } + done(); + } + }); + + function checkHapMoudleInfos(info) { + expect(info.description).assertEqual(''); + expect(info.descriptionId).assertEqual(0); + expect(info.icon).assertEqual(ICON); + expect(info.labelId).assertEqual(LABEL_ID); + expect(info.iconId).assertEqual(ICON_ID); + expect(info.label).assertEqual(LABEL); + expect(info.backgroundImg).assertEqual(""); + expect(info.supportedModes).assertEqual(0); + expect(info.reqCapabilities.length).assertEqual(0); + expect(info.deviceTypes[0]).assertEqual(DEVICE_TYPES); + expect(info.abilityInfo.length).assertLarger(0); + } +})} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/List.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0406d079c4155750f054b59f628bdb305094e29e --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/js/test/List.test.js @@ -0,0 +1,19 @@ +/* + * 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 ActsBmsHapModuleTest from './ActsBmsHapModuleTest.test.js' +export default function testsuite() { +ActsBmsHapModuleTest() +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/element/string.json b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5f41e8335254770604b7fedb8dac79712a4b0ac2 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "actsbmshapmoduletest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/media/icon.png b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmshapmoduletest/src/main/resources/base/media/icon.png differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/ActsBmsJsTest.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/ActsBmsJsTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..293b94398d922d23de8ad7cc0286923a832b2421 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/ActsBmsJsTest.test.js @@ -0,0 +1,229 @@ +/* + * 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 bundle from '@ohos.bundle' +import pkg from '@system.package' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +const NUM_TWO = 2; +const NUM_FOUR = 4; +const BUNDLE_NAME2 = 'com.example.third2'; +const BUNDLE_NAME3 = 'com.example.third5'; +const BUNDLE_NAME4 = 'com.example.js'; +const BUNDLE_NAME5 = 'com.example.c'; +const ABILITIY_NAME1 = 'com.example.third2.MainAbility'; +const ABILITIY_NAME2 = 'com.example.third5.AMainAbility'; +const ABILITIY_NAME3 = 'com.example.third5.BMainAbility'; +const ABILITIY_NAME4 = 'com.example.js.MainAbility'; +const ABILITIY_NAME5 = '.MainAbility'; +const ABILITIY_NAME6 = "com.example.third2.MainAbilityA"; +const ABILITIY_NAME7 = "com.example.third5.MainAbilityA"; +const ABILITIY_NAME8 = "com.example.third5.MainAbilityB"; + +export default function ActsBmsJsTest() { +describe('ActsBmsJsTest', function () { + + /* + * @tc.number: bms_getJsAbility_0100 + * @tc.name: test the multi js ability + * @tc.desc: 1.install a js hap which has an ability with full domain name + * 2.check the ability name by the interface of getBundleInfo + */ + it('bms_getJsAbility_0100', 0, async function (done) { + let result = await bundle.getBundleInfo(BUNDLE_NAME2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(result.abilityInfos.length).assertEqual(NUM_TWO); + if (result.abilityInfos.length == NUM_TWO) { + console.info("getBundleIno result" + JSON.stringify(result)); + let abilityInfo1 = result.abilityInfos[0]; + let abilityInfo2 = result.abilityInfos[1]; + expect(abilityInfo1.name).assertEqual(ABILITIY_NAME1); + expect(abilityInfo2.name).assertEqual(ABILITIY_NAME6); + expect(abilityInfo1.label).assertEqual("$string:app_name"); + expect(abilityInfo1.description).assertEqual("$string:mainability_description"); + expect(abilityInfo1.icon).assertEqual("$media:icon"); + expect(abilityInfo1.isVisible).assertEqual(true); + expect(abilityInfo1.permissions.length).assertEqual(0); + expect(abilityInfo1.deviceTypes[0]).assertEqual('default'); + expect(abilityInfo1.process).assertEqual(BUNDLE_NAME2); + expect(abilityInfo1.uri).assertEqual(""); + expect(abilityInfo1.bundleName).assertEqual(BUNDLE_NAME2); + expect(abilityInfo1.moduleName).assertEqual("entry"); + expect(Object.keys(abilityInfo1.applicationInfo).length).assertLarger(0); + expect(abilityInfo1.type).assertEqual(1); + expect(abilityInfo2.type).assertEqual(2); + expect(abilityInfo1.orientation).assertEqual(0); + expect(abilityInfo1.launchMode).assertEqual(1); + expect(abilityInfo1.backgroundModes).assertEqual(0); + expect(abilityInfo2.backgroundModes).assertEqual(510); + expect(abilityInfo1.descriptionId).assertLarger(0); + expect(abilityInfo1.formEnabled).assertEqual(false); + expect(abilityInfo1.iconId).assertLarger(0); + expect(abilityInfo1.labelId).assertLarger(0); + expect(abilityInfo1.subType).assertEqual(0); + expect(abilityInfo1.readPermission).assertEqual(""); + expect(abilityInfo1.writePermission).assertEqual(""); + expect(abilityInfo1.targetAbility).assertEqual(""); + expect(abilityInfo1.metaData.length).assertEqual(0); + expect(abilityInfo1.enabled).assertEqual(true); + } + done(); + }); + + /* + * @tc.number: bms_getJsAbility_0200 + * @tc.name: test the multi js ability + * @tc.desc: 1.install a js hap with two ability + * 2.check the ability name by the interface of getBundleInfo + */ + it('bms_getJsAbility_0200', 0, async function (done) { + let result = await bundle.getBundleInfo(BUNDLE_NAME3, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(result.abilityInfos.length).assertEqual(NUM_FOUR); + if (result.abilityInfos.length == NUM_FOUR) { + console.info("getBundleIno result" + JSON.stringify(result)); + let abilityInfo1 = result.abilityInfos[0]; + let abilityInfo2 = result.abilityInfos[1]; + let abilityInfo3 = result.abilityInfos[2]; + let abilityInfo4 = result.abilityInfos[3]; + checkAbilityInfos(abilityInfo1); + expect(abilityInfo2.metaData.length).assertEqual(1); + expect(abilityInfo2.metaData[0].name).assertEqual("Data5B"); + expect(abilityInfo2.metaData[0].value).assertEqual("float"); + expect(abilityInfo2.metaData[0].extra).assertEqual("$string:mainability_description"); + expect(abilityInfo2.name).assertEqual(ABILITIY_NAME3); + expect(abilityInfo3.name).assertEqual(ABILITIY_NAME7); + expect(abilityInfo4.name).assertEqual(ABILITIY_NAME8); + expect(abilityInfo3.type).assertEqual(2); + expect(abilityInfo4.type).assertEqual(2); + expect(abilityInfo3.backgroundModes).assertEqual(511); + expect(abilityInfo4.backgroundModes).assertEqual(129); + } + done(); + }); + + /* + * @tc.number: bms_getJsAbility_0300 + * @tc.name: test the multi js ability + * @tc.desc: 1.install a js hap which has an ability with short domain name + * 2.check the ability name by the interface of getBundleInfo + */ + it('bms_getJsAbility_0300', 0, async function (done) { + let result = await bundle.getBundleInfo(BUNDLE_NAME4, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(result.abilityInfos.length).assertEqual(1); + if (result.abilityInfos.length == 1) { + console.info("getBundleIno result" + JSON.stringify(result)); + let abilityInfo1 = result.abilityInfos[0]; + expect(abilityInfo1.name).assertEqual(ABILITIY_NAME4); + expect(abilityInfo1.label).assertEqual("$string:app_name"); + expect(abilityInfo1.description).assertEqual("$string:mainability_description"); + expect(abilityInfo1.icon).assertEqual("$media:icon"); + expect(abilityInfo1.isVisible).assertEqual(true); + expect(abilityInfo1.permissions.length).assertEqual(0); + expect(abilityInfo1.deviceTypes[0]).assertEqual('default'); + expect(abilityInfo1.process).assertEqual(BUNDLE_NAME4); + expect(abilityInfo1.uri).assertEqual(""); + expect(abilityInfo1.bundleName).assertEqual(BUNDLE_NAME4); + expect(abilityInfo1.moduleName).assertEqual("entry"); + expect(Object.keys(abilityInfo1.applicationInfo).length).assertLarger(0); + expect(abilityInfo1.type).assertEqual(1); + expect(abilityInfo1.orientation).assertEqual(0); + expect(abilityInfo1.launchMode).assertEqual(1); + expect(abilityInfo1.backgroundModes).assertEqual(0); + expect(abilityInfo1.descriptionId).assertLarger(0); + expect(abilityInfo1.formEnabled).assertEqual(false); + expect(abilityInfo1.iconId).assertLarger(0); + expect(abilityInfo1.labelId).assertLarger(0); + expect(abilityInfo1.subType).assertEqual(0); + expect(abilityInfo1.readPermission).assertEqual(""); + expect(abilityInfo1.writePermission).assertEqual(""); + expect(abilityInfo1.targetAbility).assertEqual(""); + expect(abilityInfo1.metaData.length).assertEqual(0); + expect(abilityInfo1.enabled).assertEqual(true); + } + done(); + }); + + /* + * @tc.number: bms_getJsAbility_0400 + * @tc.name: test the multi js ability + * @tc.desc: 1.install a c++ hap which has an ability with short domain name + * 2.check the ability name by the interface of getBundleInfo + */ + it('bms_getJsAbility_0400', 0, async function (done) { + let result = await bundle.getBundleInfo(BUNDLE_NAME5, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(result.abilityInfos.length).assertEqual(1); + if (result.abilityInfos.length == 1) { + console.info("getBundleIno result" + JSON.stringify(result)); + let abilityInfo1 = result.abilityInfos[0]; + expect(abilityInfo1.name).assertEqual(ABILITIY_NAME5); + expect(abilityInfo1.label).assertEqual("$string:app_name"); + expect(abilityInfo1.description).assertEqual("$string:mainability_description"); + expect(abilityInfo1.icon).assertEqual("$media:icon"); + expect(abilityInfo1.isVisible).assertEqual(true); + expect(abilityInfo1.permissions.length).assertEqual(0); + expect(abilityInfo1.deviceTypes[0]).assertEqual('default'); + expect(abilityInfo1.process).assertEqual(BUNDLE_NAME5); + expect(abilityInfo1.uri).assertEqual(""); + expect(abilityInfo1.bundleName).assertEqual(BUNDLE_NAME5); + expect(abilityInfo1.moduleName).assertEqual("entry"); + expect(Object.keys(abilityInfo1.applicationInfo).length).assertLarger(0); + expect(abilityInfo1.type).assertEqual(1); + expect(abilityInfo1.orientation).assertEqual(0); + expect(abilityInfo1.launchMode).assertEqual(1); + expect(abilityInfo1.backgroundModes).assertEqual(0); + expect(abilityInfo1.descriptionId).assertLarger(0); + expect(abilityInfo1.formEnabled).assertEqual(false); + expect(abilityInfo1.iconId).assertLarger(0); + expect(abilityInfo1.labelId).assertLarger(0); + expect(abilityInfo1.subType).assertEqual(0); + expect(abilityInfo1.readPermission).assertEqual(""); + expect(abilityInfo1.writePermission).assertEqual(""); + expect(abilityInfo1.targetAbility).assertEqual(""); + expect(abilityInfo1.metaData.length).assertEqual(0); + expect(abilityInfo1.enabled).assertEqual(true); + } + done(); + }); + + function checkAbilityInfos(info) { + expect(info.name).assertEqual(ABILITIY_NAME2); + expect(info.label).assertEqual("$string:app_name"); + expect(info.description).assertEqual("$string:mainability_description"); + expect(info.icon).assertEqual("$media:icon"); + expect(info.isVisible).assertEqual(true); + expect(info.permissions.length).assertEqual(0); + expect(info.deviceTypes[0]).assertEqual('default'); + expect(info.process).assertEqual(BUNDLE_NAME3); + expect(info.uri).assertEqual(""); + expect(info.bundleName).assertEqual(BUNDLE_NAME3); + expect(info.moduleName).assertEqual("entry"); + expect(Object.keys(info.applicationInfo).length).assertLarger(0); + expect(info.type).assertEqual(1); + expect(info.orientation).assertEqual(0); + expect(info.launchMode).assertEqual(1); + expect(info.backgroundModes).assertEqual(0); + expect(info.descriptionId).assertLarger(0); + expect(info.formEnabled).assertEqual(false); + expect(info.iconId).assertLarger(0); + expect(info.labelId).assertLarger(0); + expect(info.subType).assertEqual(0); + expect(info.readPermission).assertEqual(""); + expect(info.writePermission).assertEqual(""); + expect(info.targetAbility).assertEqual(""); + expect(info.metaData.length).assertEqual(1); + expect(info.metaData[0].name).assertEqual("Data5A"); + expect(info.metaData[0].value).assertEqual("float"); + expect(info.metaData[0].extra).assertEqual("$string:mainability_description"); + expect(info.enabled).assertEqual(true); + } +})} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/List.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/List.test.js index f4720e369f106714465bfbc763dce70ecbebb409..86489f50230a3a7ecdbfa4bd139866daefd7a9e5 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/List.test.js +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsjstest/src/main/js/test/List.test.js @@ -13,7 +13,9 @@ * limitations under the License. */ -import ActsBmsHasInstalldTest from './ActsBmsHasInstalldTest.test.js' +import ActsBmsHasInstalldTest from './ActsBmsJsTest.test.js' +import ActsBmsJsTest from './ActsBmsHasInstalldTest.test.js' export default function testsuite() { ActsBmsHasInstalldTest() +ActsBmsJsTest() } diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/src/main/js/test/ActsBmsJsUnPermissionTest.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/src/main/js/test/ActsBmsJsUnPermissionTest.test.js index eb5ae8dfcfac2f71c4ee6454943f90ec167ddeca..ca78ebec87d0f2180ff597f67cf258a4737aa503 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/src/main/js/test/ActsBmsJsUnPermissionTest.test.js +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/src/main/js/test/ActsBmsJsUnPermissionTest.test.js @@ -37,6 +37,142 @@ describe('ActsBmsJsUnPermissionTest', function () { }) }); + /* + * @tc.number: getApplicationInfo_1900 + * @tc.name: getApplicationInfoUnPermissionUserId + * @tc.desc: test getApplicationInfo + */ + it('getApplicationInfoUnPermissionUserId', 0, async function (done) { + await bundle.getApplicationInfo(LAUNCHER_BUNDLE_NAME, DEFAULT_FLAG, userId).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(INVALID_CODE); + }); + bundle.getApplicationInfo(LAUNCHER_BUNDLE_NAME, DEFAULT_FLAG, userId, (err, data) => { + expect(err.code).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: getApplicationInfos_1500 + * @tc.name: getApplicationInfosUnPermissionUserId + * @tc.desc: test getAllApplicationInfo + */ + it('getApplicationInfosUnPermissionUserId', 0, async function (done) { + await bundle.getAllApplicationInfo(DEFAULT_FLAG, userId).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(INVALID_CODE); + }); + bundle.getAllApplicationInfo(DEFAULT_FLAG, userId, (err, data) => { + expect(err.code).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: getBundleInfo_2300 + * @tc.name: getBundleInfoUnPermissionUserId + * @tc.desc: test getBundleInfo + */ + it('getBundleInfoUnPermissionUserId', 0, async function (done) { + await bundle.getBundleInfo(LAUNCHER_BUNDLE_NAME, userId).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err).assertEqual(INVALID_CODE); + }); + bundle.getBundleInfo(LAUNCHER_BUNDLE_NAME, userId, (err, data) => { + expect(err).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: getBundleInfos_1000 + * @tc.name: getAllBundleInfoUnPermission + * @tc.desc: test getAllBundleInfo + */ + it('getAllBundleInfoUnPermission', 0, async function (done) { + await bundle.getAllBundleInfo(DEFAULT_FLAG).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err).assertEqual(INVALID_CODE); + }); + bundle.getAllBundleInfo(DEFAULT_FLAG, (err, data) => { + expect(err).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0015 + * @tc.name: queryAbilityByWantUnPermission + * @tc.desc: test queryAbilityByWant + */ + it('queryAbilityByWantUnPermission', 0, async function (done) { + await bundle.queryAbilityByWant({ + bundleName: LAUNCHER_BUNDLE_NAME, + abilityName: LAUNCHER_MAIN_ABILITY + }, DEFAULT_FLAG, userId).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err).assertEqual(INVALID_CODE); + }); + bundle.queryAbilityByWant({ + bundleName: LAUNCHER_BUNDLE_NAME, + abilityName: LAUNCHER_MAIN_ABILITY + }, DEFAULT_FLAG, userId, (err, data) => { + console.info("data ===================:" + data); + expect(err).assertEqual(INVALID_CODE); + expect(data).assertEqual("QueryAbilityInfos failed"); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0010 + * @tc.name: getLaunchWantForBundleUnPermission + * @tc.desc: test getLaunchWantForBundle + */ + it('getLaunchWantForBundleUnPermission', 0, async function (done) { + await bundle.getLaunchWantForBundle(LAUNCHER_BUNDLE_NAME).then(data => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(INVALID_CODE); + }); + bundle.getLaunchWantForBundle(LAUNCHER_BUNDLE_NAME, (err, data) => { + expect(err.code).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_GETABILITYLABELP_0006 + * @tc.name: getAbilityLabelUnPermission + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it('getAbilityLabelUnPermission', 0, async function (done) { + await bundle.getAbilityLabel(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY) + .then((data) => { + expect().assertFail(); + }) + .catch((error) => { + expect(error).assertEqual(INVALID_CODE); + }); + bundle.getAbilityLabel(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY, (err, data) => { + expect(err).assertEqual(INVALID_CODE); + expect(data).assertEqual(undefined); + done(); + }); + }); + /* * @tc.number: SUB_BMS_APPINFO_GETABILITYINFO_0006 * @tc.name: getAbilityInfoUnPermission diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/BUILD.gn b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..99231471ee62e940e350871cad25aafd90741d2e --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/BUILD.gn @@ -0,0 +1,35 @@ +# 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("ActsBmsMetaDataTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsBmsMetaDataTest" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" +} +ohos_js_assets("hjs_demo_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/Test.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..8d4f9e90c44520d9e6f3f8de6e6e9141cec8ebac --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/Test.json @@ -0,0 +1,60 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "com.example.actsbmsmetadatatest", + "package-name": "com.example.actsbmsmetadatatest" + }, + "kits": [ + { + "test-file-name": [ + "ActsBmsMetaDataTest.hap", + "bmsSystemBundleTest1.hap", + "bmsVendorBundleTest1.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/test" + ] + }, + { + "type": "PushKit", + "push": [ + "bmsThirdBundleTest1.hap->/data/test/bmsThirdBundleTest1.hap", + "bmsThirdBundleTestA1.hap->/data/test/bmsThirdBundleTestA1.hap", + "bmsThirdBundleTest5.hap->/data/test/bmsThirdBundleTest5.hap", + "bmsSystemBundleTest1.hap->/data/test/bmsSystemBundleTest1.hap", + "bmsVendorBundleTest1.hap->/data/test/bmsVendorBundleTest1.hap", + "first_right.hap->/data/test/first_right.hap", + "second_right.hap->/data/test/second_right.hap" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "bm install -p /data/test/bmsThirdBundleTest1.hap", + "bm install -p /data/test/bmsThirdBundleTestA1.hap", + "bm install -p /data/test/bmsSystemBundleTest1.hap", + "bm install -p /data/test/bmsVendorBundleTest1.hap", + "bm install -p /data/test/bmsThirdBundleTest5.hap", + "bm install -p /data/test/first_right.hap", + "bm install -p /data/test/second_right.hap" + ], + "teardown-command": [ + "bm uninstall -n com.example.third1", + "bm uninstall -n com.example.system1", + "bm uninstall -n com.example.vendor1", + "bm uninstall -n com.example.third5", + "bm uninstall -n com.example.l3jsdemo", + "rm -rf /data/test/" + ] + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/signature/openharmony_sx.p7b b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..3a7eb6dc682f3ce734ec103281c9727559e00085 Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/signature/openharmony_sx.p7b differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/config.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..191acc789ccf95f3094a414671285a2ad141d650 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/config.json @@ -0,0 +1,101 @@ +{ + "app": { + "bundleName": "com.example.actsbmsmetadatatest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.actsbmsmetadatatest", + "name": ".entry", + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO", + "reason": "need use ohos.permission.GET_BUNDLE_INFO" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..c158442201abb1888ae8fb1d57f150c5ec26c36b --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* + * 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('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..01ad739b27f208ff04f21924695104bd27c59df0 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,24 @@ +/* +* 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. +*/ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f99407c7e17ea547a58e64b3ef573867ebcb6918 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,20 @@ + + +
+ + {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..361b8367ff1f01e418d56760ac500e7e64a678f2 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,33 @@ +/* + * 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. + */ + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: 'Test MetaData' + }, + onInit() { + this.title = 'Test MetaData'; + }, + onShow() { + console.info('onReady finish') + }, + onReady() { + }, + onBackPress(){ + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/app.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ee271df29e516d1c8929054283e5f2bf5c981c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/en-US.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/zh-CN.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.css b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b21c92c6290ea747bd891e2ab673721afc5521ed --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.hml b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d94b75c085fa1c16a0b2721609b18c57a7295476 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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 default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..b9e78ce7cf73f1ade6ba52a408a44e33f5430f0d --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/ActsBmsMetaDataTest.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/ActsBmsMetaDataTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0463971d98cf200acc310c365c00b51514744a07 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/ActsBmsMetaDataTest.test.js @@ -0,0 +1,228 @@ +/* + * 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 bundle from '@ohos.bundle' +import account from '@ohos.account.osAccount' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +const BUNDLE_NAME1 = 'com.example.third1'; +const BUNDLE_NAME2 = 'com.example.third5'; +const BUNDLE_NAME3 = 'com.example.noexist'; +const BUNDLE_NAME4 = 'com.example.system1'; +const BUNDLE_NAME5 = 'com.example.vendor1'; +const BUNDLE_NAME6 = 'com.example.l3jsdemo'; +const ABILITY_NAME1 = 'com.example.third1.MainAbility'; +const ABILITY_NAME2 = 'com.example.third5.AMainAbility'; +const ABILITY_NAME3 = 'com.example.noexist.MainAbility'; +const ABILITY_NAME4 = 'com.example.system1.MainAbility'; +const ABILITY_NAME5 = 'com.example.vendor1.MainAbility'; +const ABILITY_NAME6 = 'com.example.l3jsdemo.MainAbility'; +let userId = 0; + +export default function ActsBmsMetaDataTest() { +describe('ActsBmsMetaDataTest', function () { + + beforeAll(async function (done) { + await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { + console.info("getOsAccountLocalIdFromProcess userid ==========" + account); + userId = account; + done(); + }).catch(err=>{ + console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); + done(); + }) + }); + + /* + * @tc.number: bms_getMetaData_0100 + * @tc.name: test to get meta data for an application. + * @tc.desc: get an ability's meta data when update. + */ + it('bms_getMetaData_0100', 0, async function (done) { + await bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME1, + "abilityName": ABILITY_NAME1 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("DataA1"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + }).catch(err => { + expect(err).assertFail(); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME1, + "abilityName": ABILITY_NAME1 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("DataA1"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + done(); + }); + }); + + /* + * @tc.number: bms_getMetaData_0200 + * @tc.name: test to get meta data for an application. + * @tc.desc: get an ability's meta data which contains two HAP packages. + */ + it('bms_getMetaData_0200', 0, async function (done) { + await bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME6, + "abilityName": ABILITY_NAME6 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + let metaDataInfo = dataInfos[0].metaData; + expect(metaDataInfo[0].name).assertEqual("Data3"); + expect(metaDataInfo[0].value).assertEqual("float"); + expect(metaDataInfo[0].extra).assertEqual("$string:mainability_description"); + }).catch(err => { + expect(err).assertFail(); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME6, + "abilityName": ABILITY_NAME6 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("Data3"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + done(); + }); + }); + + /* + * @tc.number: bms_getMetaData_0400 + * @tc.name: test to get meta data for an application. + * @tc.desc: get an ability's meta data which has two ability. + */ + it('bms_getMetaData_0400', 0, async function (done) { + await bundle.queryAbilityByWant( + { + bundleName: BUNDLE_NAME2, + abilityName: ABILITY_NAME2, + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("Data5A"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + }).catch(err => { + expect(err).assertFail(); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME2, + "abilityName": ABILITY_NAME2 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("Data5A"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + done(); + }); + }); + + /* + * @tc.number: bms_getMetaData_0500 + * @tc.name: test to get meta data for an application that does not exist. + * @tc.desc: get an ability's meta data which does not exist. + */ + it('bms_getMetaData_0500', 0, async function (done) { + await bundle.queryAbilityByWant( + { + bundleName: BUNDLE_NAME3, + abilityName: ABILITY_NAME3, + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + expect(dataInfos).assertFail(); + }).catch(err => { + expect(err).assertEqual(1); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME3, + "abilityName": ABILITY_NAME3 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + expect(err).assertEqual(1); + expect(dataInfos).assertEqual("QueryAbilityInfos failed"); + done(); + }); + }); + + /* + * @tc.number: bms_getMetaData_0600 + * @tc.name: test to get meta data for a system application. + * @tc.desc: get a system ability's meta data. + */ + it('bms_getMetaData_0600', 0, async function (done) { + await bundle.queryAbilityByWant( + { + bundleName: BUNDLE_NAME4, + abilityName: ABILITY_NAME4, + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("Data1S"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + }).catch(err => { + expect(err).assertFail(); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME4, + "abilityName": ABILITY_NAME4 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("Data1S"); + expect(metaData[0].value).assertEqual("float"); + expect(metaData[0].extra).assertEqual("$string:mainability_description"); + done(); + }); + }); + + /* + * @tc.number: bms_getMetaData_0700 + * @tc.name: test to get meta data for a vendor application. + * @tc.desc: get a vendor ability's meta data. + */ + it('bms_getMetaData_0700', 0, async function (done) { + await bundle.queryAbilityByWant( + { + bundleName: BUNDLE_NAME5, + abilityName: ABILITY_NAME5, + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId).then(dataInfos => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("vendorName"); + expect(metaData[0].value).assertEqual("vendorValue"); + expect(metaData[0].extra).assertEqual("vendorcustomizeData"); + }).catch(err => { + expect(err).assertFail(); + }); + bundle.queryAbilityByWant( + { + "bundleName": BUNDLE_NAME5, + "abilityName": ABILITY_NAME5 + }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, userId, (err, dataInfos) => { + let metaData = dataInfos[0].metaData; + expect(metaData[0].name).assertEqual("vendorName"); + expect(metaData[0].value).assertEqual("vendorValue"); + expect(metaData[0].extra).assertEqual("vendorcustomizeData"); + done(); + }); + }); +})} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/List.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0e3f700e9950297a520fbb0ee9d9e3643e3fcb0c --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/js/test/List.test.js @@ -0,0 +1,18 @@ +/* + * 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 ActsBmsMetaDataTest from './ActsBmsMetaDataTest.test.js' +export default function testsuite() { +ActsBmsMetaDataTest() +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/element/string.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2670b1b49275d3ce1068a188086c6f72e64fcf33 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "actsbmsmetadatatest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/media/icon.png b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/bundlemanager/bundle_standard/bundlemanager/actsbmsmetadatatest/src/main/resources/base/media/icon.png differ diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityIcon.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityIcon.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..264547f71b905679487117dfc82d97126d2af3dc --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityIcon.test.ets @@ -0,0 +1,164 @@ +/* + * 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 bundle from '@ohos.bundle' +import image from '@ohos.multimedia.image' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' + +const BUNDLE_NAME = "com.open.harmony.packagemag"; +const ABILITIY_NAME = "com.open.harmony.packagemag.MainAbility"; +const SERVICE_NAME = "com.open.harmony.packagemag.ServiceAbility"; +const BUNDLE_NAME_OTHER = "com.example.l3jsdemo"; +const ABILITIY_NAME_OTHER = "com.example.l3jsdemo.MainAbility"; +const BUNDLE_NAME_ERROR = "com.ohos.packagemag"; +const ABILITIY_NAME_ERROR = "com.ohos.packagemag.MainAbility"; + +export default function getAbilityIcon() { + describe('ActsBmsGetAbilityIconTest', function () { + + /* + * @tc.number: bms_getAbilityIcon_0100 + * @tc.name: test getAbilityIcon + * @tc.desc: get the abilityIcon + */ + it('bms_getAbilityIcon_0100', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER).then(pixelmap => { + console.log('bms_getAbilityIcon_0100 success: ' + pixelmap.getBytesNumberPerRow()); + expect(pixelmap.getBytesNumberPerRow()).assertLarger(0); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertFail(); + }); + bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER, (err, pixelmap) => { + expect(err).assertEqual(0); + expect(pixelmap.getBytesNumberPerRow()).assertLarger(0); + done(); + }); + }); + + /* + * @tc.number: bms_getAbilityIcon_0200 + * @tc.name: test getAbilityIcon + * @tc.desc: get the abilityIcon + */ + it('bms_getAbilityIcon_0200', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME).then(pixelmap => { + console.log('bms_getAbilityIcon_0200 success: ' + pixelmap.getBytesNumberPerRow()); + expect(pixelmap.getBytesNumberPerRow()).assertLarger(0); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertFail(); + }); + bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME, (err, pixelmap) => { + expect(err).assertEqual(0); + expect(pixelmap.getBytesNumberPerRow()).assertLarger(0); + done(); + }); + }); + + /* + * @tc.number: bms_getAbilityIcon_0300 + * @tc.name: test getAbilityIcon + * @tc.desc: get the abilityIcon + */ + it('bms_getAbilityIcon_0300', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME, SERVICE_NAME).then(pixelmap => { + expect().assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertEqual(1); + }); + bundle.getAbilityIcon(BUNDLE_NAME, SERVICE_NAME, (err, pixelmap) => { + expect(err).assertEqual(1); + done(); + }); + }); + + /* + * @tc.number: bms_getAbilityIcon_0400 + * @tc.name: test getAbilityIcon + * @tc.desc: get the abilityIcon + */ + it('bms_getAbilityIcon_0400', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME_ERROR).then(pixelmap => { + expect(pixelmap !== null).assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)) + expect(err).assertEqual(1); + }); + await bundle.getAbilityIcon(BUNDLE_NAME_ERROR, ABILITIY_NAME).then(pixelmap => { + expect().assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)) + expect(err).assertEqual(1); + }); + await bundle.getAbilityIcon("", "").then(pixelmap => { + expect().assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)) + expect(err).assertEqual(1); + }); + bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME_ERROR, (err, pixelmap) => { + console.log('bms_getAbilityIcon_0100 success: ' + pixelmap); + expect(err).assertEqual(1); + bundle.getAbilityIcon(BUNDLE_NAME_ERROR, ABILITIY_NAME, (err, pixelmap) => { + expect(err).assertEqual(1); + bundle.getAbilityIcon("", "", (err, pixelmap) => { + expect(err).assertEqual(1); + done(); + }); + }); + }); + }); + + /* + * @tc.number: bms_getAbilityIcon_0500 + * @tc.name: test getAbilityIcon + * @tc.desc: get the abilityIcon + */ + it('bms_getAbilityIcon_0500', 0, async function (done) { + await bundle.getAbilityIcon(BUNDLE_NAME, undefined).then(pixelmap => { + expect(pixelmap).assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertEqual(2); + }); + await bundle.getAbilityIcon(undefined, ABILITIY_NAME).then(pixelmap => { + expect(pixelmap).assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertEqual(2); + }); + await bundle.getAbilityIcon(undefined, undefined).then(pixelmap => { + expect(pixelmap).assertFail(); + }).catch(err => { + console.info("getAbilityIcon fail:" + JSON.stringify(err)); + expect(err).assertEqual(2); + }); + bundle.getAbilityIcon(BUNDLE_NAME, undefined, (err, pixelmap) => { + console.log('bms_getAbilityIcon_0100 success: ' + pixelmap); + expect(err).assertEqual(2); + bundle.getAbilityIcon(undefined, ABILITIY_NAME, (err, pixelmap) => { + expect(err).assertEqual(2); + bundle.getAbilityIcon(undefined, undefined, (err, pixelmap) => { + expect(err).assertEqual(2); + done(); + }); + }); + }); + }); + + }); +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityLabelJsUnit.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityLabelJsUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..faf159447d0a3e0d259d7e82c88d679fcc13e09a --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetAbilityLabelJsUnit.test.ets @@ -0,0 +1,163 @@ +/** + * 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 'hypium/index'; +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.example.l3jsdemo'; +const OTHER_ABILITY_NAME = 'com.example.l3jsdemo.MainAbility'; +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'; +const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'; + +export default function getAbilityLabel() { + + describe('getAbilityLabel_test', function () { + + + /* + * @tc.number: getAbilityLabel_test_0100 + * @tc.name: Test getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface + */ + it('getAbilityLabel_test_0100', 0, async function (done) { + await Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME).then((data) => { + expect(data).assertEqual("entry_MainAbility"); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME, (error, data) => { + expect(error).assertNull(); + expect(data).assertEqual("entry_MainAbility"); + done(); + }); + }); + + /* + * @tc.number: getAbilityLabel_test_0200 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface + */ + it('getAbilityLabel_test_0200', 0, async function (done) { + let timeOldStamp = await Utils.getNowTime(); + await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME).then((data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp); + expect(data).assertEqual("bmsfirstright"); + }).catch((error) => { + expect(error).assertFail(); + }); + timeOldStamp = await Utils.getNowTime(); + Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME, (error, data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp); + expect(data).assertEqual("bmsfirstright"); + expect(error).assertNull(); + done(); + }); + }); + + /* + * @tc.number: getAbilityLabel_test_0300 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface + */ + it('getAbilityLabel_test_0300', 0, async function (done) { + await Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error).assertEqual(1); + }); + Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME, (error, data) => { + expect(error).assertEqual(1); + expect(data).assertEqual(undefined); + done(); + }); + }); + + /* + * @tc.number: getAbilityLabel_test_0400 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface + */ + it('getAbilityLabel_test_0400', 0, async function (done) { + let timeOldStamp = await Utils.getNowTime(); + await Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp); + expect(error).assertEqual(1); + }); + await Bundle.getAbilityLabel("", "").then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error).assertEqual(1); + }); + timeOldStamp = await Utils.getNowTime(); + Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR, (error, data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp); + expect(error).assertEqual(1); + expect(data).assertEqual(undefined); + Bundle.getAbilityLabel("", "", (error, data) => { + expect(error).assertEqual(1); + expect(data).assertEqual(undefined); + done(); + }); + }); + }); + + /* + * @tc.number: getAbilityLabel_test_0500 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface + */ + it('getAbilityLabel_test_0500', 0, async function (done) { + await Bundle.getAbilityLabel(undefined, OTHER_ABILITY_NAME).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error).assertEqual(2); + }); + await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, undefined).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error).assertEqual(2); + }); + await Bundle.getAbilityLabel(undefined, undefined).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error).assertEqual(2); + }); + Bundle.getAbilityLabel(undefined, OTHER_ABILITY_NAME, (error, data) => { + expect(error).assertEqual(2); + expect(data).assertEqual(undefined); + Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, undefined, (error, data) => { + expect(error).assertEqual(2); + expect(data).assertEqual(undefined); + Bundle.getAbilityLabel(undefined, undefined, (error, data) => { + expect(error).assertEqual(2); + expect(data).assertEqual(undefined); + done(); + }); + }); + }); + }); + + }) + +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetLaunchWantForBundle.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetLaunchWantForBundle.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c8efeabcc9344e8e3e7e4635782c6fffa67c3c4e --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetLaunchWantForBundle.test.ets @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file expect 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 bundleMgr from '@ohos.bundle'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'; + +const NAME1 = "com.example.third1"; +const NAME2 = "com.example.l3jsdemo"; +const NAME3 = "com.notexist.com"; +const ABILITYNAME1 = "com.example.third1.MainAbility"; +const ABILITYNAME2 = "com.example.l3jsdemo.MainAbility"; + +export default function getLaunchWantForBundle() { + describe('GetLaunchWantForBundleTest', function () { + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0069 + * @tc.name: testGetLaunchWantForBundle. + * @tc.desc: Test getLaunchWantForBundle api by promise and callback. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 1 + */ + it('testGetLaunchWantForBundle', 0, async function (done) { + await bundleMgr.getLaunchWantForBundle(NAME1).then(res => { + expect(res.bundleName).assertEqual(NAME1); + expect(res.abilityName).assertEqual(ABILITYNAME1); + expect(res.deviceId).assertEqual(''); + expect(res.action).assertEqual('action.system.home'); + expect(res.entities[0]).assertEqual('entity.system.home'); + }).catch(err => { + expect(err).assertFail(); + }); + bundleMgr.getLaunchWantForBundle(NAME1, (err, res) => { + expect(err.code).assertEqual(0); + expect(res.bundleName).assertEqual(NAME1); + expect(res.abilityName).assertEqual(ABILITYNAME1); + expect(res.deviceId).assertEqual(''); + expect(res.action).assertEqual('action.system.home'); + expect(res.entities[0]).assertEqual('entity.system.home'); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0012 + * @tc.name: testGetLaunchWantForBundleWithManyHaps. + * @tc.desc: Test getLaunchWantForBundle api by promise and callback. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 1 + */ + it('testGetLaunchWantForBundleWithManyHaps', 0, async function (done) { + await bundleMgr.getLaunchWantForBundle(NAME2).then(res => { + expect(res.bundleName).assertEqual(NAME2); + expect(res.abilityName).assertEqual(ABILITYNAME2); + expect(res.deviceId).assertEqual(''); + expect(res.action).assertEqual('action.system.home'); + expect(res.entities[0]).assertEqual('entity.system.home'); + }).catch(err => { + expect(err).assertFail(); + }); + bundleMgr.getLaunchWantForBundle(NAME2, (err, res) => { + expect(err.code).assertEqual(0); + expect(res.bundleName).assertEqual(NAME2); + expect(res.abilityName).assertEqual(ABILITYNAME2); + expect(res.deviceId).assertEqual(''); + expect(res.action).assertEqual('action.system.home'); + expect(res.entities[0]).assertEqual('entity.system.home'); + done(); + }); + }); + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0013 + * @tc.name: testGetLaunchWantForBundleWithNotExist. + * @tc.desc: Test getLaunchWantForBundle api by promise and callback. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('testGetLaunchWantForBundleWithNotExist', 0, async function (done) { + await bundleMgr.getLaunchWantForBundle(NAME3).then(res => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(1); + }); + bundleMgr.getLaunchWantForBundle(NAME3, (err, res) => { + if (err) { + expect(err.code).assertEqual(1); + done(); + return; + } + expect().assertFail(); + done(); + }); + }); + + /* + * @tc.number: SUB_BMS_APPINFO_QUERY_0014 + * @tc.name: testGetLaunchWantForBundleWithInvalidParam. + * @tc.desc: Test getLaunchWantForBundle api by promise and callback. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 3 + */ + it('testGetLaunchWantForBundleWithInvalidParam', 0, async function (done) { + await bundleMgr.getLaunchWantForBundle(null).then(res => { + expect().assertFail(); + }).catch(err => { + expect(err.code).assertEqual(1); + }); + bundleMgr.getLaunchWantForBundle(null, (err, res) => { + if (err) { + expect(err.code).assertEqual(1); + done(); + return; + } + expect().assertFail(); + done(); + }); + }); + }); +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetNameForUid.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetNameForUid.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6735a77f5c93685e6dab9a486c4757c55b6ec136 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetNameForUid.test.ets @@ -0,0 +1,106 @@ +/* + * 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 bundle from '@ohos.bundle' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' + +const BUNDLE_NAME1 = 'com.example.l3jsdemo'; +const BUNDLE_NAME2 = 'com.open.harmony.packagemag'; + +export default function getNameForUid() { + describe('ActsBmsgetNameForUidTest', function () { + + /** + * @tc.number getNameForUid_0100 + * @tc.name BUNDLE::getBundleInfo + * @tc.desc Test getBundleInfo interfaces with other hap. + */ + it('getNameForUid_0100', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME1, bundle.BundleFlag.GET_BUNDLE_DEFAULT); + await bundle.getNameForUid(dataInfo.uid).then(data => { + expect(data).assertEqual(BUNDLE_NAME1); + }).catch(err => { + console.info("getNameForUid fail:" + JSON.stringify(err)); + expect(err).assertFail(); + }); + bundle.getNameForUid(dataInfo.uid, (err, data) => { + console.info("getNameForUid result:" + JSON.stringify(data)); + expect(data).assertEqual(BUNDLE_NAME1); + expect(err).assertEqual(0); + done(); + }); + }); + + /** + * @tc.number getNameForUid_0200 + * @tc.name BUNDLE::getBundleInfo + * @tc.desc Test getBundleInfo interfaces with hap. + */ + it('getNameForUid_0200', 0, async function (done) { + let dataInfo = await bundle.getBundleInfo(BUNDLE_NAME2,bundle.BundleFlag.GET_BUNDLE_DEFAULT); + await bundle.getNameForUid(dataInfo.uid).then(data => { + expect(data).assertEqual(BUNDLE_NAME2); + }).catch(err => { + console.info("getNameForUid fail:" + JSON.stringify(err)); + expect(err).assertFail(); + }); + bundle.getNameForUid(dataInfo.uid, (err, data) => { + console.info("getNameForUid result:" + JSON.stringify(data)); + expect(data).assertEqual(BUNDLE_NAME2); + expect(err).assertEqual(0); + done(); + }); + }); + + /** + * @tc.number getNameForUid_0300 + * @tc.name BUNDLE::getBundleInfo + * @tc.desc Test getBundleInfo interfaces with notexist hap. + */ + it('getNameForUid_0300', 0, async function (done) { + await bundle.getNameForUid(123456).then(data => { + expect(data).assertFail(); + }).catch(err => { + console.info("getNameForUid fail:" + JSON.stringify(err)); + expect(err).assertEqual(1); + }); + bundle.getNameForUid(123456, (err, data) => { + console.info("getNameForUid result:" + JSON.stringify(data)); + expect(err).assertEqual(1); + done() + }); + }); + + /** + * @tc.number getNameForUid_0400 + * @tc.name BUNDLE::getBundleInfo + * @tc.desc Test getBundleInfo interfaces with error param. + */ + it('getNameForUid_0400', 0, async function (done) { + await bundle.getNameForUid(undefined).then(data => { + expect(data).assertFail(); + }).catch(err => { + console.info("getNameForUid fail:" + JSON.stringify(err)); + expect(err).assertEqual(2); + }); + bundle.getNameForUid(undefined, (err, data) => { + console.info("getNameForUid result:" + JSON.stringify(data)); + expect(err).assertEqual(2); + done() + }); + }); + + }); +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetQueryAbilityByWant.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetQueryAbilityByWant.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4242b68b67f88b269339fe272bb7c850b38d7c95 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/GetQueryAbilityByWant.test.ets @@ -0,0 +1,1015 @@ +/* + * 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 bundle from '@ohos.bundle' +import account from '@ohos.account.osAccount' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' + +const BUNDLE_NAME1 = 'com.example.third1'; +const SYSTEM_NAME = 'com.example.system2'; +const ABILITIY_NAME8 = 'com.example.system2.MainAbility'; +let userId: number = 0; +const INVALID_CODE: number = 1; + +export default function ActsBmsQueryAbilityByWant() { + describe('ActsBmsQueryAbilityByWant', function () { + + beforeAll(async function (done) { + await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { + console.info("getOsAccountLocalIdFromProcess userid ==========" + account); + userId = account; + done(); + }).catch(err => { + console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); + done(); + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0100 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0100', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0200 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0200', 0, async function (done) { + bundle.queryAbilityByWant( + {}, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0300 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0300', 0, async function (done) { + bundle.queryAbilityByWant( + { + action: "action_a" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_0300'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.actionSingleString') + expect(res[0].description).assertEqual('actionSingleString') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0300' + JSON.stringify(err)) + expect().assertFail() + done() + }) + + }); + + /* + * @tc.number: bms_queryAbilityByWant_0400 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0400', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "action_b2" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_0400'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.actionDoubleString') + expect(res[0].description).assertEqual('actionDoubleString') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0400' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0500 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0500', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "action_c1" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_0500'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.actionDoubleSkill') + expect(res[0].description).assertEqual('actionDoubleSkill') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0500' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0600 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third appl + */ + it('bms_queryAbilityByWant_0600', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "action_d2" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_0600'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.actionDoubleSkill') + expect(res[0].description).assertEqual('actionDoubleSkill') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0600' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + + /* + * @tc.number: bms_queryAbilityByWant_0700 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0700', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "action_not_exist" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0700' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0800 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0800', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": [] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_0800 '+ JSON.stringify(res)) + const list = ['entityDoubleSkill','entityDoubleString','entitySingleString','entityEmpty'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0800 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_0900 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_0900', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": [""] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_0900' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1000 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1000', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_a"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1000'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.entitySingleString') + expect(res[0].description).assertEqual('entitySingleString') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1000' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1100 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1100', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_b2"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1100'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.entityDoubleString') + expect(res[0].description).assertEqual('entityDoubleString') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1100' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1200 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1200', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_d1"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1200'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.entityDoubleSkill') + expect(res[0].description).assertEqual('entityDoubleSkill') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1200' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1300 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1300', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_c1", "entity_c2"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1300'+ JSON.stringify(res)) + expect(res[0].name).assertEqual('com.example.third7.entityDoubleSkill') + expect(res[0].description).assertEqual('entityDoubleSkill') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1300' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1400 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1400', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_b1", "entity_not_exist"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1400' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1500 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1500', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_b1", "entity_b2", "entity_not_exist"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1500' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1600 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1600', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + "entities": ["entity_not_exist"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1600' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1700 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1700', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "entity_reserved", + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1700 '+ JSON.stringify(res)) + const list = ['entityDoubleSkill','entityDoubleString','entitySingleString','entityEmpty'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1700 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1800 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1800', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1800 '+ JSON.stringify(res)) + const list = ['uriEmpty','uriSchemeEmpty'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1800 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_1900 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_1900', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_1900 '+ JSON.stringify(res)) + const list = ['uriHostEmpty','uriScheme'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_1900 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2000 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2000', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2000 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriSchemeHost') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2000 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2100 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2100', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com:8080" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2100 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriSchemeHostPort') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2100 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2200 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2200', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com:8080/query/student/name" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2200 '+ JSON.stringify(res)) + const list = ['uriSchemeHostPortPath','uriSchemeHostPortPathStartWith','uriSchemeHostPortPathRegx'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2200 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2300 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2300', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com/query/student/name" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2300 '+ JSON.stringify(res)) + const list = ['uriPortEmptyWithPath','uriPortEmptyWithPathStartWith','uriPortEmptyWithPathRegx'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2300 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2400 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2400', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com:8080/query/teacher/name" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2400 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriSchemeHostPortPathRegx') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2400 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2500 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2500', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://www.test.com:8080/query/student/jack" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2500 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriSchemeHostPortPathStartWith') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2500 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2600 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2600', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "file://www.test.com:8080/query/student/name" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2600 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriMultiPath') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2600 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2700 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2700', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "file://www.test.com:8080/query/teacher/hello" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2700 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('uriMultiPath') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2700 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2800 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2800', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "uri_reserved", + "uri": "content://abc" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + expect(res).assertFail() + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2800' + JSON.stringify(err)) + expect(err).assertEqual(INVALID_CODE) + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_2900 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_2900', 0, async function (done) { + bundle.queryAbilityByWant( + { + "type": "*/*" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_2900 '+ JSON.stringify(res)) + const list = ['TypeDoubleWildCard','TypeSingleWildCard','TypeString', 'TypeStringExt'] + let cnt = 0; + if (res && res.length) { + for (let i = 0; i < res.length; i++) { + if (list.includes(res[i].description)) { + cnt++; + } + } + } + expect(cnt).assertEqual(list.length) + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_2900' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3000 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3000', 0, async function (done) { + bundle.queryAbilityByWant( + { + "type": "prefixType/*" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3000 '+ JSON.stringify(res)) + const list = ['TypeDoubleWildCard','TypeSingleWildCard','TypeString'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3000 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3100 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3100', 0, async function (done) { + bundle.queryAbilityByWant( + { + "type": "prefixType/suffixType" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3100 '+ JSON.stringify(res)) + const list = ['TypeDoubleWildCard','TypeSingleWildCard','TypeString'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3100' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3200 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3200', 0, async function (done) { + bundle.queryAbilityByWant( + { + "type": "prefixTypeExt/suffixTypeExt" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3200 '+ JSON.stringify(res)) + const list = ['TypeStringExt','TypeDoubleWildCard'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3200' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3300 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3300', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "type_reserved" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3300 '+ JSON.stringify(res)) + const list = ['TypeEmpty','TypeEmptyExt'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3300 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3400 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3400', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "type_reserved", + "type": "" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3400 '+ JSON.stringify(res)) + const list = ['TypeEmpty','TypeEmptyExt'] + if(res && res.length) { + for(let i = 0; i < res.length; i++) { + expect(list.includes(res[i].description)).assertEqual(true) + } + } + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3400 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3500 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3500', 0, async function (done) { + bundle.queryAbilityByWant( + { + "type": "none/none" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3500'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('TypeDoubleWildCard') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3500' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3600 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3600', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "all_action_a", + "entities":["all_entity_a"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3600'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allAE') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3600' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3700 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3700', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action": "all_action_b", + "entities":["all_entity_b1", "all_entity_b2"] + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3700'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allAEs') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3700' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3800 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3800', 0, async function (done) { + bundle.queryAbilityByWant( + { + "uri" :"http://www.test.com:8080/query/student/name", + "type":"text/plain" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3800'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3800' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_3900 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_3900', 0, async function (done) { + bundle.queryAbilityByWant( + { + "uri" :"http://www.test.com:8080/query/student/name", + "type":"text/*" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_3900'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_3900' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_4000 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_4000', 0, async function (done) { + bundle.queryAbilityByWant( + { + "uri" :"http://www.test.com:8080/query/teacher", + "type":"text/plain" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_4000'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_4000' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_4100 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_4100', 0, async function (done) { + bundle.queryAbilityByWant( + { + "uri" :"http://www.test.com:8080/query/teacher/hello", + "type":"text/plain" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_4100'+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_4100' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_4200 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_4200', 0, async function (done) { + bundle.queryAbilityByWant( + { + "uri" :"http://www.test.com:8080/update/hello/world/name", + "type":"text/plain" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_4200 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_4200 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_4300 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_4300', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action":"all_action_c", + "entities":["all_entity_c1"], + "uri" :"https://www.test.com:8080/query/student/name", + "type":"text/plain" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_4300 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allAEUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_4300 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + + /* + * @tc.number: bms_queryAbilityByWant_4400 + * @tc.name: Use the implicit query method in queryAbilityByWant to get abilityInfos + * @tc.desc: queryAbilityByWant for third app + */ + it('bms_queryAbilityByWant_4400', 0, async function (done) { + bundle.queryAbilityByWant( + { + "action":"all_action_c", + "entities":["all_entity_c1", "all_entity_c2"], + "uri" :"https://www.test.com:8080/query/student/name", + "type":"text/*" + }, bundle.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(res => { + console.info(' success bms_queryAbilityByWant_4400 '+ JSON.stringify(res)) + expect(res[0].description).assertEqual('allAEUT') + done() + }).catch(err => { + console.error(' fail bms_queryAbilityByWant_4400 ' + JSON.stringify(err)) + expect().assertFail() + done() + }) + }); + }) +} diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsAbilityEnabledETSUnit.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsAbilityEnabledETSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ec5645a797e25302b841f752b352df56445a0c5 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsAbilityEnabledETSUnit.ets @@ -0,0 +1,244 @@ +/** + * 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 'hypium/index'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag'; +const BUNDLE_NAME_OTHER = 'com.example.l3jsdemo'; +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'; +const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility'; +const ABILITY_NAME_OTHER = 'com.example.l3jsdemo.MainAbility'; +const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'; +const ABILITY_ERROR1 = { + bundleName: BUNDLE_NAME_ERROR, + name: ABILITY_NAME_ERROR +}; +const ABILITY_ERROR2 = { + bundleName: "", + name: ABILITY_NAME +}; +const ABILITY_ERROR3 = { + bundleName: BUNDLE_NAME, + name: "" +}; +const ABILITY_ERROR4 = { + bundleName: undefined, + name: ABILITY_NAME +}; +const ABILITY_ERROR5 = { + bundleName: BUNDLE_NAME, + name: undefined +}; +const ABILITY_ERROR6 = { + bundleName: undefined, + name: undefined +}; +const ABILITY_ERROR7 = { + bundleName: "", + name: "" +}; + + +export default function isAbilityEnabledETSUnit() { + + describe('isAbilityEnabled_test', function () { + + /* + * @tc.number: isAbilityEnabled_test_0100 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface + */ + it('isAbilityEnabled_test_0100', 0, async function (done) { + let timeOldStamp = await Utils.getNowTime(); + let abilityInfo = generateAbilityInfoForTest(BUNDLE_NAME,ABILITY_NAME); + await Bundle.isAbilityEnabled(abilityInfo).then((data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp); + expect(data).assertTrue(); + }).catch((error) => { + expect(error).assertFail(); + }); + timeOldStamp = await Utils.getNowTime(); + Bundle.isAbilityEnabled(abilityInfo, (error, data) => { + if (error.code != 0) { + expect(error).assertFail(); + } + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp); + expect(data).assertTrue(); + done(); + }); + }); + + /* + * @tc.number: isAbilityEnabled_test_0200 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface when bundleName and ability error + */ + it('isAbilityEnabled_test_0200', 0, async function (done) { + let abilityInfo1 = generateAbilityInfoForTest(ABILITY_ERROR1.bundleName,ABILITY_ERROR1.name); + let abilityInfo2 = generateAbilityInfoForTest(ABILITY_ERROR2.bundleName,ABILITY_ERROR2.name); + let abilityInfo3 = generateAbilityInfoForTest(ABILITY_ERROR3.bundleName,ABILITY_ERROR3.name); + let abilityInfo7 = generateAbilityInfoForTest(ABILITY_ERROR7.bundleName,ABILITY_ERROR7.name); + Bundle.isAbilityEnabled(abilityInfo1).then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.isAbilityEnabled(abilityInfo2).then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.isAbilityEnabled(abilityInfo3).then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.isAbilityEnabled(abilityInfo7).then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.isAbilityEnabled(abilityInfo1, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + Bundle.isAbilityEnabled(abilityInfo2, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + Bundle.isAbilityEnabled(abilityInfo3, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + Bundle.isAbilityEnabled(abilityInfo7, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + done(); + }); + }); + }); + }); + }); + + /* + * @tc.number: isAbilityEnabled_test_0300 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface when bundleName and ability error + */ + it('isAbilityEnabled_test_0300', 0, async function (done) { + let abilityInfo4 = generateAbilityInfoForTest(ABILITY_ERROR4.bundleName,ABILITY_ERROR4.name); + let abilityInfo5 = generateAbilityInfoForTest(ABILITY_ERROR5.bundleName,ABILITY_ERROR5.name); + let abilityInfo6 = generateAbilityInfoForTest(ABILITY_ERROR6.bundleName,ABILITY_ERROR6.name); + Bundle.isAbilityEnabled(abilityInfo4).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error.code).assertEqual(2); + }); + Bundle.isAbilityEnabled(abilityInfo5).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error.code).assertEqual(2); + }); + Bundle.isAbilityEnabled(abilityInfo6).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error.code).assertEqual(2); + }); + Bundle.isAbilityEnabled(abilityInfo4, (error, data) => { + expect(error.code).assertEqual(2); + expect(data).assertEqual(undefined); + Bundle.isAbilityEnabled(abilityInfo5, (error, data) => { + expect(error.code).assertEqual(2); + expect(data).assertEqual(undefined); + Bundle.isAbilityEnabled(abilityInfo6, (error, data) => { + expect(error.code).assertEqual(2); + expect(data).assertEqual(undefined); + done(); + }); + }); + }); + }); + + /* + * @tc.number: isAbilityEnabled_test_0400 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface + */ + it('isAbilityEnabled_test_0400', 0, async function (done) { + let abilityInfo = generateAbilityInfoForTest(BUNDLE_NAME_OTHER,ABILITY_NAME_OTHER); + await Bundle.isAbilityEnabled(abilityInfo).then((data) => { + expect(data).assertTrue(); + }).catch((error) => { + expect(error).assertFail(); + }); + Bundle.isAbilityEnabled(abilityInfo, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertTrue(); + done(); + }); + }); + + function generateAbilityInfoForTest(bundleName, name) { + let map1 = new Map([ + ["", [{ + "name": "", "value": "", "extra": "" + }]] + ]); + let map2 = new Map([ + ["", [{ + "name": "", "value": "", "resource": "" + }]] + ]); + let resource = { + "bundleName": "", "moduleName": "", "id": 0 + } + let abilityInfo = { + bundleName: bundleName, + name: name, + label: "", + description: "", + icon: "", + labelId: 0, + descriptionId: 0, + iconId: 0, + moduleName: "", + process: "", + targetAbility: "", + backgroundModes: 0, + isVisible: true, + formEnabled: true, + type: 0, + subType: 0, + orientation: 0, + launchMode: 0, + permissions: [], deviceTypes: [], deviceCapabilities: [], readPermission: "", writePermission: "", + applicationInfo: { + name: "", description: "", descriptionId: 0, systemApp: true, enabled: true, label: "", + labelId: "", labelIndex: 0, icon: "", iconId: "", iconIndex: 0, process: "", supportedModes: 0, moduleSourceDirs: [], + permissions: [], moduleInfos: [], entryDir: "", codePath: "", metaData: map1, metadata: map2, + removable: true, accessTokenId: 0, uid: 0, entityType: "", fingerprint: "", + iconResource: resource, labelResource: resource, descriptionResource: resource, + appDistributionType :"" ,appProvisionType :"" + }, + uri: "", metaData: [], metadata: [], enabled: true, supportWindowMode: [], + maxWindowRatio: 0, minWindowRatio: 0, maxWindowWidth: 0, minWindowWidth: 0, maxWindowHeight: 0, minWindowHeight: 0 + }; + return abilityInfo; + } + + + + }) +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsApplicationEnabledETSUnit.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsApplicationEnabledETSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..10b74064b7a49f985003383f1fd3908a719fec31 --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/IsApplicationEnabledETSUnit.ets @@ -0,0 +1,109 @@ +/** + * 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 'hypium/index'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag'; +const BUNDLE_NAME_OTHER = 'com.example.l3jsdemo'; +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'; + +export default function IsApplicationEnabledETSUnit() { + + describe('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) + */ + it('isApplicationEnabled_test_0100', 0, async function (done) { + let timeOldStamp = await Utils.getNowTime(); + await Bundle.isApplicationEnabled(BUNDLE_NAME).then((data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[isApplicationEnabled_test_0100]', timeOldStamp, timeNewStamp); + expect(data).assertTrue(); + }).catch((error) => { + expect(error).assertFail(); + }); + timeOldStamp = await Utils.getNowTime(); + Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => { + let timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0200]', timeOldStamp, timeNewStamp); + expect(error.code).assertEqual(0); + expect(data).assertTrue(); + done(); + }); + }); + + /* + * @tc.number: isApplicationEnabled_test_0200 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by promise) + */ + it('isApplicationEnabled_test_0200', 0, async function (done) { + await Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR).then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + await Bundle.isApplicationEnabled("").then((data) => { + expect(data).assertFalse(); + }).catch((error) => { + expect(error).assertFail(); + }); + await Bundle.isApplicationEnabled(undefined).then((data) => { + expect(data).assertFail(); + }).catch((error) => { + expect(error.code).assertEqual(2); + }); + Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + Bundle.isApplicationEnabled("", (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertFalse(); + Bundle.isApplicationEnabled(undefined, (error, data) => { + expect(error.code).assertEqual(2); + expect(data).assertEqual(undefined); + done(); + }); + }); + }); + }); + + /* + * @tc.number: isApplicationEnabled_test_0300 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by promise) + */ + it('isApplicationEnabled_test_0300', 0, async function (done) { + let timeOldStamp = await Utils.getNowTime(); + await Bundle.isApplicationEnabled(BUNDLE_NAME_OTHER).then((data) => { + expect(data).assertTrue(); + }).catch((error) => { + expect(error).assertFail(); + }); + timeOldStamp = await Utils.getNowTime(); + Bundle.isApplicationEnabled(BUNDLE_NAME_OTHER, (error, data) => { + expect(error.code).assertEqual(0); + expect(data).assertTrue(); + done(); + }); + }); + + }) + +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/List.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/List.test.ets index b9346eeb54bdc525dc6ac3479bfd0ccbbc7dc146..7bdefdf5c76f3550bf4786f8b71cd7b426b55d55 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/List.test.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/List.test.ets @@ -12,16 +12,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import getLaunchWantForBundle from './GetLaunchWantForBundle.test.ets'; 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"; +import getAbilityIcon from "./GetAbilityIcon.test.ets"; +import getNameForUid from "./GetNameForUid.test.ets"; +import getBundleArchiveInfo from "./getBundleArchiveInfo.test.ets"; +import getQueryAbilityByWant from './GetQueryAbilityByWant.test.ets'; import isDefaultApplicationTest from './IsDefaultApplication.test.ets'; import getBundleInfoForSelf from './GetBundleInfoForSelf.test.ets'; export default function testsuite() { getBundleInfoForSelf(); + getBundleArchiveInfo(); + getAbilityIcon(); + getLaunchWantForBundle(); + getNameForUid(); + getQueryAbilityByWant(); isDefaultApplicationTest(); getApplicationInfoJsunit(); getAllAppInfoJsunit(); getabilityInfo(); + + getAbilityLabelJsUnit(); + + isAbilityEnableETSUnit(); + isApplicationEnabledETSUnit(); } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/getBundleArchiveInfo.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/getBundleArchiveInfo.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fddc4d637ab3d3abf3ab0aadafa5ac52cb9c596f --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/test/getBundleArchiveInfo.test.ets @@ -0,0 +1,343 @@ +/** + * 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 bundle from '@ohos.bundle'; +import { describe, beforeAll, it, expect } from 'hypium/index'; + +const PATH = "/data/test/" +const ERROR = "error.hap" +const BMSJSTEST1 = "bmsJstest1.hap" +const BMSJSTEST2 = "bmsJstest2.hap" +const BMSJSTEST3 = "bmsJstest3.hap" +const BMSJSTEST4 = "bmsJstest4.hap" +const BMSJSTEST5 = "bmsJstest5.hap" +const BMSJSTEST6 = "bmsJstest6.hap" +const NAME1 = "com.example.myapplication1" +const NAME2 = "com.example.myapplication2" +const NAME3 = "com.example.myapplication4" +const NAME4 = "com.example.myapplication5" +const NAME5 = "com.example.myapplication6" +const DESCRIPTION = "$string:mainability_description" +const APPLICATION_DESCRIPTION = "$string:entry_description" + +export default function getBundleArchiveInfo() { + + describe('getBundleArchiveInfo', function () { + + /** + * @tc.number getBundleArchiveInfo_0100 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with one hap. + */ + it('getBundleArchiveInfo_0100', 0, async function (done) { + let datainfo = await bundle.getBundleArchiveInfo(PATH + BMSJSTEST1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES) + expect(datainfo.name).assertEqual(NAME1) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertLarger(0) + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + done(); + }) + + /** + * @tc.number getBundleArchiveInfo_0200 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with two haps. + */ + it('getBundleArchiveInfo_0200', 0, async function (done) { + let datainfo = await bundle.getBundleArchiveInfo(PATH + BMSJSTEST2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES) + expect(datainfo.name).assertEqual(NAME2) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertLarger(0) + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + done(); + }) + + /** + * @tc.number getBundleArchiveInfo_0300 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with three haps. + */ + it('getBundleArchiveInfo_0300', 0, async function (done) { + let datainfo = await bundle.getBundleArchiveInfo(PATH + BMSJSTEST4, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES) + expect(datainfo.name).assertEqual(NAME3) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertLarger(0) + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + done(); + }) + + /** + * @tc.number getBundleArchiveInfo_0400 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with error hap. + */ + it('getBundleArchiveInfo_0400', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + ERROR, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(datainfo => { + console.info("getBundleArchiveInfo success" + JSON.stringify(datainfo)) + expect(datainfo).assertFail() + done() + }).catch(err => { + console.info("getBundleArchiveInfo fail" + JSON.stringify(err)) + expect(err.code).assertEqual(1) + done() + }) + }) + + /** + * @tc.number getBundleArchiveInfo_0500 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with none hap. + */ + it('getBundleArchiveInfo_0500', 0, async function (done) { + let datainfo = await bundle.getBundleArchiveInfo(' ', bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(datainfo => { + console.info("getBundleArchiveInfo success" + JSON.stringify(datainfo)) + expect(datainfo).assertFail() + done() + }).catch(err => { + console.info("getBundleArchiveInfo fail" + JSON.stringify(err)) + expect(err.code).assertEqual(1) + done() + }) + }) + + /** + * @tc.number getBundleArchiveInfo_0600 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with none hap. + */ + it('getBundleArchiveInfo_0600', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + BMSJSTEST1, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + expect(datainfo.name).assertEqual(NAME1) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertEqual("1.0") + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.name).assertEqual(NAME1) + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + expect(datainfo.appInfo.supportedModes).assertEqual(0) + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry") + } + for (let j = 0; j < datainfo.abilityInfos.length; j++) { + expect(datainfo.abilityInfos[j].name).assertEqual("com.example.myapplication1.MainAbility") + expect(datainfo.abilityInfos[j].label).assertEqual("$string:app_name") + expect(datainfo.abilityInfos[j].description).assertEqual(DESCRIPTION) + expect(datainfo.abilityInfos[j].icon).assertEqual("$media:icon") + expect(datainfo.abilityInfos[j].isVisible).assertEqual(false) + expect(datainfo.abilityInfos[j].bundleName).assertEqual(NAME1) + expect(datainfo.abilityInfos[j].moduleName).assertEqual("entry") + } + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_0700 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with two hap. + */ + it('getBundleArchiveInfo_0700', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + BMSJSTEST2, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + expect(datainfo.name).assertEqual(NAME2) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertLarger(0) + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_0800 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with one hap. + */ + it('getBundleArchiveInfo_0800', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + BMSJSTEST4, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + expect(datainfo.name).assertEqual(NAME3) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertLarger(0) + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_0900 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with error hap. + */ + it('getBundleArchiveInfo_0900', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + ERROR, bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + if (err) { + console.info("getBundleArchiveInfo error" + JSON.stringify(err)); + expect(err.code).assertEqual(1); + done(); + return; + } + console.info("getBundleArchiveInfo sucess" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_1000 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with none hap. + */ + it('getBundleArchiveInfo_1000', 0, async function (done) { + await bundle.getBundleArchiveInfo(' ', bundle.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + if (err) { + console.info("getBundleArchiveInfo error" + JSON.stringify(err)); + expect(err.code).assertEqual(1); + done(); + return; + } + console.info("getBundleArchiveInfo sucess" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_1100 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with none hap. + */ + it('getBundleArchiveInfo_1100', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + BMSJSTEST1, bundle.BundleFlag.GET_BUNDLE_DEFAULT, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + expect(datainfo.name).assertEqual(NAME1) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertEqual("1.0") + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.name).assertEqual(NAME1) + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + expect(datainfo.appInfo.supportedModes).assertEqual(0) + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry") + } + for (let j = 0; j < datainfo.abilityInfos.length; j++) { + expect(datainfo.abilityInfos[j].name).assertEqual(".MainAbility") + expect(datainfo.abilityInfos[j].label).assertEqual("$string:app_name") + expect(datainfo.abilityInfos[j].description).assertEqual(DESCRIPTION) + expect(datainfo.abilityInfos[j].icon).assertEqual("$media:icon") + expect(datainfo.abilityInfos[j].isVisible).assertEqual(false) + expect(datainfo.abilityInfos[j].bundleName).assertEqual(NAME1) + expect(datainfo.abilityInfos[j].moduleName).assertEqual("entry") + } + done(); + } + }) + + /** + * @tc.number getBundleArchiveInfo_1200 + * @tc.name BUNDLE::getBundleArchiveInfo + * @tc.desc Test getBundleArchiveInfo interfaces with none hap. + */ + it('getBundleArchiveInfo_1200', 0, async function (done) { + await bundle.getBundleArchiveInfo(PATH + BMSJSTEST1, bundle.BundleFlag.GET_BUNDLE_DEFAULT, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + expect(datainfo.name).assertEqual(NAME1) + expect(datainfo.vendor).assertEqual("example") + expect(datainfo.versionCode).assertEqual(1) + expect(datainfo.versionName).assertEqual("1.0") + expect(datainfo.entryModuleName).assertEqual("entry") + expect(datainfo.appInfo.name).assertEqual(NAME1) + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION) + expect(datainfo.appInfo.descriptionId >= 0).assertTrue() + expect(datainfo.appInfo.icon).assertEqual("$media:icon") + expect(parseInt(datainfo.appInfo.iconId)).assertLarger(0) + expect(datainfo.appInfo.label).assertEqual("$string:app_name") + expect(parseInt(datainfo.appInfo.labelId)).assertLarger(0) + expect(datainfo.appInfo.systemApp).assertEqual(false) + expect(datainfo.appInfo.supportedModes).assertEqual(0) + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry") + } + for (let j = 0; j < datainfo.abilityInfos.length; j++) { + expect(datainfo.abilityInfos[j].name).assertEqual(".MainAbility") + expect(datainfo.abilityInfos[j].label).assertEqual("$string:app_name") + expect(datainfo.abilityInfos[j].description).assertEqual(DESCRIPTION) + expect(datainfo.abilityInfos[j].icon).assertEqual("$media:icon") + expect(datainfo.abilityInfos[j].isVisible).assertEqual(false) + expect(datainfo.abilityInfos[j].bundleName).assertEqual(NAME1) + expect(datainfo.abilityInfos[j].moduleName).assertEqual("entry") + } + done(); + } + }) + + + }) +} \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanagertest/src/main/js/test/ExampleJsunit.test.js b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanagertest/src/main/js/test/ExampleJsunit.test.js index ea2a8fc39aa455c8e2c89801bbe3372a2707d815..14261daabd2d57026f55857417e31571b5f99bf3 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbundlemanagertest/src/main/js/test/ExampleJsunit.test.js +++ b/bundlemanager/bundle_standard/bundlemanager/actsbundlemanagertest/src/main/js/test/ExampleJsunit.test.js @@ -18,10 +18,1775 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from import demo from '@ohos.bundle' import account from '@ohos.account.osAccount' +const ERROR = "error.hap" +const NAME1 = "com.example.myapplication1" +const NAME2 = "com.example.myapplication2" +const NAME3 = "com.example.myapplication4" +const NAME4 = "com.example.myapplication5" +const NAME5 = "com.example.myapplication6" +const VERSIONCODE1 = 1 +const OBJECT = "object" +const DIR1 = "/data/app/el1/bundle/public/com.example.myapplication1/com.example.myapplication1" +const DIR2 = "/data/app/el1/bundle/public/com.example.myapplication2/com.example.myapplication2" +const DIR3 = "/data/app/el1/bundle/public/com.example.myapplication2/com.example.myapplication1" +const DESCRIPTION = "$string:mainability_description" +const APPLICATION_DESCRIPTION = "$string:entry_description" +let userId = 0; export default function ActsBundleManagerTest() { describe('ActsBundleManagerTest', function () { + beforeAll(async function (done) { + await account.getAccountManager().getOsAccountLocalIdFromProcess().then(account => { + console.info("getOsAccountLocalIdFromProcess userid ==========" + account); + userId = account; + done(); + }).catch(err => { + console.info("getOsAccountLocalIdFromProcess err ==========" + JSON.stringify(err)); + done(); + }) + }); + + /** + * @tc.number getBundleInfo_0100 + * @tc.name testGetBundleInfoReqPermissionPromise + * @tc.desc Test getBundleInfo interfaces with one hap.(by promise) + */ + it('testGetBundleInfoReqPermissionPromise', 0, async function (done) { + let datainfo = await demo.getBundleInfo(NAME1, + demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES | demo.BundleFlag.GET_BUNDLE_WITH_REQUESTED_PERMISSION); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertEqual("1.0"); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.uid).assertLarger(0); + expect(datainfo.appId).assertContain(NAME1); + expect(datainfo.type).assertEqual(""); + expect(datainfo.cpuAbi).assertEqual(""); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + expect(datainfo.installTime).assertLarger(0); + expect(datainfo.updateTime).assertLarger(0); + expect(datainfo.reqPermissions[0]).assertEqual("com.permission.PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].name).assertEqual("com.permission.PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].reason).assertEqual("Need PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].usedScene.abilities[0]).assertEqual(NAME1 + ".MainAbility"); + expect(datainfo.reqPermissionDetails[0].usedScene.when).assertEqual("always"); + expect(datainfo.reqPermissionDetails[0].reasonId).assertEqual(0); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.isCompressNativeLibs).assertEqual(true); + for (let s = 0; s < datainfo.hapModuleInfos.length; s++) { + expect(datainfo.hapModuleInfos[s].name).assertEqual("com.example.myapplication1.MyApplication1"); + expect(datainfo.hapModuleInfos[s].moduleName).assertEqual("entry"); + } + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.isSilentInstallation.length).assertEqual(0); + expect(datainfo.minCompatibleVersionCode).assertEqual(1); + expect(datainfo.entryInstallationFree).assertEqual(false); + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + }) + + /** + * @tc.number getBundleInfo_0600 + * @tc.name testGetBundeInfoReqPermissionCallback + * @tc.desc Test getBundleInfo interfaces with one hap.(by callback) + */ + it('testGetBundeInfoReqPermissionCallback', 0, async function (done) { + await demo.getBundleInfo(NAME1, + demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES | demo.BundleFlag.GET_BUNDLE_WITH_REQUESTED_PERMISSION, + OnReceiveEvent); + function OnReceiveEvent(err, datainfo) { + checkBundleInfo0200(datainfo) + done(); + } + }) + + function checkBundleInfo0200(datainfo) { + console.info("testGetBundeInfoReqPermissionCallback dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertEqual("1.0"); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.uid).assertLarger(0); + expect(datainfo.appId).assertContain(NAME1); + expect(datainfo.type).assertEqual(""); + expect(datainfo.cpuAbi).assertEqual(""); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + expect(datainfo.installTime).assertLarger(0); + expect(datainfo.updateTime).assertLarger(0); + expect(datainfo.reqPermissions[0]).assertEqual("com.permission.PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].name).assertEqual("com.permission.PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].reason).assertEqual("Need PERMISSION_A"); + expect(datainfo.reqPermissionDetails[0].usedScene.abilities[0]).assertEqual(NAME1 + ".MainAbility"); + expect(datainfo.reqPermissionDetails[0].usedScene.when).assertEqual("always"); + expect(datainfo.reqPermissionDetails[0].reasonId).assertEqual(0); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.isCompressNativeLibs).assertEqual(true); + for (let s = 0; s < datainfo.hapModuleInfos.length; s++) { + expect(datainfo.hapModuleInfos[s].name).assertEqual("com.example.myapplication1.MyApplication1"); + expect(datainfo.hapModuleInfos[s].moduleName).assertEqual("entry"); + } + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.isSilentInstallation.length).assertEqual(0); + expect(datainfo.minCompatibleVersionCode).assertEqual(1); + expect(datainfo.entryInstallationFree).assertEqual(false); + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(datainfo.appInfo.enabled).assertEqual(true); + } + + /** + * @tc.number getBundleInfo_0200 + * @tc.name testGetBundleInfoMultiHapPromise + * @tc.desc Test getBundleInfo interfaces with two haps.(by promise) + */ + it('testGetBundleInfoMultiHapPromise', 0, async function (done) { + let datainfo = await demo.getBundleInfo(NAME2, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + console.info("testGetBundleInfoMultiHapPromise dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME2); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(1); + expect(datainfo.versionName).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.appInfo.name).assertEqual(NAME2); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + done(); + }) + + /** + * @tc.number getBundleInfo_0700 + * @tc.name testGetBundleInfoMultiHapCallback + * @tc.desc Test getBundleInfo interfaces with two haps.(by callback) + */ + it('testGetBundleInfoMultiHapCallback', 0, async function (done) { + await demo.getBundleInfo(NAME2, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent); + function OnReceiveEvent(err, datainfo) { + console.info("testGetBundleInfoMultiHapCallback dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME2); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(1); + expect(datainfo.versionName).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.appInfo.name).assertEqual(NAME2); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + done(); + } + }) + + /** + * @tc.number getBundleInfo_0300 + * @tc.name testGetBundleInfoPromise + * @tc.desc Test getBundleInfo interfaces with one hap. (by promise) + */ + it('testGetBundleInfoPromise', 0, async function (done) { + let datainfo = await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + console.info("testGetBundleInfoPromise dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertEqual("1.0"); + expect(datainfo.type).assertEqual(""); + expect(datainfo.cpuAbi).assertEqual(""); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.installTime).assertLarger(0); + expect(datainfo.updateTime).assertLarger(0); + expect(datainfo.uid).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.minCompatibleVersionCode).assertEqual(1); + expect(datainfo.entryInstallationFree).assertEqual(false); + expect(datainfo.reqPermissions.length).assertEqual(0); + expect(datainfo.reqPermissionStates.length).assertEqual(0); + expect(datainfo.reqPermissionDetails.length).assertEqual(0); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + }) + + /** + * @tc.number getBundleInfo_0800 + * @tc.name testGetBundleInfoCallback + * @tc.desc Test getBundleInfo interfaces with one hap. (by callback) + */ + it('testGetBundleInfoCallback', 0, async function (done) { + await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES | + demo.BundleFlag.GET_ABILITY_INFO_WITH_DISABLE, OnReceiveEvent); + function OnReceiveEvent(err, datainfo) { + console.info("testGetBundleInfoCallback dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertEqual("1.0"); + expect(datainfo.type).assertEqual(""); + expect(datainfo.cpuAbi).assertEqual(""); + expect(datainfo.compatibleVersion).assertEqual(5); + expect(datainfo.targetVersion).assertEqual(5); + expect(datainfo.installTime).assertLarger(0); + expect(datainfo.updateTime).assertLarger(0); + expect(datainfo.uid).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.minCompatibleVersionCode).assertEqual(1); + expect(datainfo.entryInstallationFree).assertEqual(false); + expect(datainfo.reqPermissions.length).assertEqual(0); + expect(datainfo.reqPermissionStates.length).assertEqual(0); + expect(datainfo.reqPermissionDetails.length).assertEqual(0); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + } + }) + + /** + * @tc.number getBundleInfo_0400 + * @tc.name testGetBundleInfoNotExistPromise + * @tc.desc Test getBundleInfo interfaces with error hap. (by promise) + */ + it('testGetBundleInfoNotExistPromise', 0, async function (done) { + await demo.getBundleInfo('error', demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(datainfo => { + console.info("testGetBundleInfoNotExistPromise success:" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }).catch(err => { + console.info("testGetBundleInfoNotExistPromise err:" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + }); + }) + + /** + * @tc.number getBundleInfo_0900 + * @tc.name testGetBundleInfoNotExistCallback + * @tc.desc Test getBundleInfo interfaces with error hap. (by callback) + */ + it('testGetBundleInfoNotExistCallback', 0, async function (done) { + await demo.getBundleInfo('error', demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent); + function OnReceiveEvent(err, datainfo) { + if (err) { + console.info("testGetBundleInfoNotExistCallback err" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + return; + } + console.info("testGetBundleInfoNotExistCallback success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + } + }) + + /** + * @tc.number getBundleInfo_0500 + * @tc.name testGetBundleInfoInvalidParamPromise + * @tc.desc Test getBundleInfo interfaces with none hap. (by promise) + */ + it('testGetBundleInfoInvalidParamPromise', 0, async function (done) { + await demo.getBundleInfo(' ', demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(datainfo => { + console.info("testGetBundleInfoInvalidParamPromise success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }).catch(err => { + console.info("testGetBundleInfoInvalidParamPromise fail" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + }); + }) + + /** + * @tc.number getBundleInfo_1000 + * @tc.name testGetBundleInfoInvalidParamCallback + * @tc.desc Test getBundleInfo interfaces with none hap. (by callback) + */ + it('testGetBundleInfoInvalidParamCallback', 0, async function (done) { + await demo.getBundleInfo(' ', demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, OnReceiveEvent); + function OnReceiveEvent(err, datainfo) { + if (err) { + console.info("testGetBundleInfoInvalidParamCallback err" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + return; + } + console.info("testGetBundleInfoInvalidParamCallback success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + } + }) + + /** + * @tc.number getBundleInfo_1100 + * @tc.name testGetBundleInfoDifferentParamPromise + * @tc.desc Test getBundleInfo interfaces with one hap and different param. (by promise) + */ + it('testGetBundleInfoDifferentParamPromise', 0, async function (done) { + let datainfo = await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_DEFAULT) + console.info("testGetBundleInfoDifferentParamPromise dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + }) + + /** + * @tc.number getBundleInfo_1200 + * @tc.name testGetBundleInfoDifferentParamCallback + * @tc.desc Test getBundleInfo interfaces with one hap and different param. (by callback) + */ + it('testGetBundleInfoDifferentParamCallback', 0, async function (done) { + await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_DEFAULT, OnReceiveEvent) + function OnReceiveEvent(err, datainfo) { + console.info("testGetBundleInfoDifferentParamCallback dataInfo ====" + datainfo); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(VERSIONCODE1); + expect(datainfo.versionName).assertLarger(0); + expect(datainfo.entryModuleName).assertEqual("entry"); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.appInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.appInfo.icon).assertEqual("$media:icon"); + expect(datainfo.appInfo.iconId >= 0).assertTrue(); + expect(datainfo.appInfo.label).assertEqual("$string:app_name"); + expect(datainfo.appInfo.labelId >= 0).assertTrue(); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + for (let j = 0; j < datainfo.appInfo.moduleInfos.length; j++) { + expect(datainfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + } + }) + + /** + * @tc.number getBundleInfo_1300 + * @tc.name testGetBundleInfoSystemAppCallback + * @tc.desc Test getBundleInfo interfaces with systemApp.(by callback) + */ + it('testGetBundleInfoSystemAppCallback', 0, async function (done) { + let bundleOptions = { + userId: userId + }; + demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, + bundleOptions, (err, datainfo) => { + if (err) { + console.info("testGetBundleInfoSystemAppCallback fail:" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + return; + } + console.info("testGetBundleInfoSystemAppCallback success:" + JSON.stringify(datainfo)); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.vendor).assertEqual("example"); + expect(datainfo.versionCode).assertEqual(1); + expect(datainfo.versionName.length).assertLarger(0); + expect(datainfo.uid).assertLarger(2099); + expect(datainfo.appInfo.name).assertEqual(NAME1); + expect(datainfo.appInfo.systemApp).assertEqual(false); + expect(datainfo.appInfo.supportedModes).assertEqual(0); + expect(datainfo.appInfo.moduleInfos.length).assertLarger(0); + expect(datainfo.appInfo.enabled).assertEqual(true); + done(); + }) + }) + + /** + * @tc.number getBundleInfo_1400 + * @tc.name testGetBundleInfoCurrentUserIdPromise + * @tc.desc Test getBundleInfo interface with current userId (by promise). + */ + it('testGetBundleInfoCurrentUserIdPromise', 0, async function (done) { + let bundleOptions = { + userId: userId + }; + let dataInfo = await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, bundleOptions); + console.info("testGetBundleInfoCurrentUserIdPromise start --------"); + console.info("testGetBundleInfoCurrentUserIdPromise dataInfo ====" + dataInfo); + expect(dataInfo.name).assertEqual(NAME1); + expect(dataInfo.vendor).assertEqual("example"); + expect(dataInfo.versionCode).assertEqual(VERSIONCODE1); + expect(dataInfo.versionName).assertLarger(0); + expect(dataInfo.entryModuleName).assertEqual("entry"); + expect(dataInfo.appInfo.name).assertEqual(NAME1); + expect(dataInfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(dataInfo.appInfo.descriptionId >= 0).assertTrue(); + expect(dataInfo.appInfo.icon).assertEqual("$media:icon"); + expect(dataInfo.appInfo.iconId >= 0).assertTrue(); + expect(dataInfo.appInfo.label).assertEqual("$string:app_name"); + expect(dataInfo.appInfo.labelId >= 0).assertTrue(); + expect(dataInfo.appInfo.systemApp).assertEqual(false); + expect(dataInfo.appInfo.supportedModes).assertEqual(0); + expect(dataInfo.updateTime).assertLarger(0); + expect(dataInfo.reqPermissions.length).assertEqual(0); + expect(dataInfo.reqPermissionDetails.length).assertEqual(0); + expect(dataInfo.compatibleVersion).assertEqual(5); + expect(dataInfo.targetVersion).assertEqual(5); + expect(dataInfo.isCompressNativeLibs).assertEqual(true); + for (let s = 0; s < dataInfo.hapModuleInfos.length; s++) { + expect(dataInfo.hapModuleInfos[s].name).assertEqual("com.example.myapplication1.MyApplication1"); + expect(dataInfo.hapModuleInfos[s].moduleName).assertEqual("entry"); + } + expect(dataInfo.entryModuleName).assertEqual("entry"); + expect(dataInfo.isSilentInstallation.length).assertEqual(0); + expect(dataInfo.minCompatibleVersionCode).assertEqual(1); + expect(dataInfo.entryInstallationFree).assertEqual(false); + for (let j = 0; j < dataInfo.appInfo.moduleInfos.length; j++) { + expect(dataInfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(dataInfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + expect(dataInfo.appInfo.enabled).assertEqual(true); + console.info("testGetBundleInfoCurrentUserIdPromise end --------"); + done(); + }) + + /** + * @tc.number getBundleInfo_1500 + * @tc.name testGetBundleInfoCurrentUserIdCallback + * @tc.desc Test getBundleInfo interface with current userId (by callback). + */ + it('testGetBundleInfoCurrentUserIdCallback', 0, async function (done) { + let bundleOptions = { + userId: userId + }; + demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, bundleOptions, (err, dataInfo) => { + console.info("testGetBundleInfoCurrentUserIdCallback start --------"); + console.info("testGetBundleInfoCurrentUserIdCallback dataInfo ====" + dataInfo); + expect(dataInfo.name).assertEqual(NAME1); + expect(dataInfo.vendor).assertEqual("example"); + expect(dataInfo.versionCode).assertEqual(VERSIONCODE1); + expect(dataInfo.versionName).assertLarger(0); + expect(dataInfo.entryModuleName).assertEqual("entry"); + expect(dataInfo.appInfo.name).assertEqual(NAME1); + expect(dataInfo.appInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(dataInfo.appInfo.descriptionId >= 0).assertTrue(); + expect(dataInfo.appInfo.icon).assertEqual("$media:icon"); + expect(dataInfo.appInfo.iconId >= 0).assertTrue(); + expect(dataInfo.appInfo.label).assertEqual("$string:app_name"); + expect(dataInfo.appInfo.labelId >= 0).assertTrue(); + expect(dataInfo.appInfo.systemApp).assertEqual(false); + expect(dataInfo.appInfo.supportedModes).assertEqual(0); + expect(dataInfo.updateTime).assertLarger(0); + expect(dataInfo.reqPermissions.length).assertEqual(0); + expect(dataInfo.reqPermissionDetails.length).assertEqual(0); + expect(dataInfo.compatibleVersion).assertEqual(5); + expect(dataInfo.targetVersion).assertEqual(5); + expect(dataInfo.isCompressNativeLibs).assertEqual(true); + for (let s = 0; s < dataInfo.hapModuleInfos.length; s++) { + expect(dataInfo.hapModuleInfos[s].name).assertEqual("com.example.myapplication1.MyApplication1"); + expect(dataInfo.hapModuleInfos[s].moduleName).assertEqual("entry"); + } + expect(dataInfo.entryModuleName).assertEqual("entry"); + expect(dataInfo.isSilentInstallation.length).assertEqual(0); + expect(dataInfo.minCompatibleVersionCode).assertEqual(1); + expect(dataInfo.entryInstallationFree).assertEqual(false); + for (let j = 0; j < dataInfo.appInfo.moduleInfos.length; j++) { + expect(dataInfo.appInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(dataInfo.appInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + console.info("testGetBundleInfoCurrentUserIdCallback end --------"); + done(); + }); + }) + + /** + * @tc.number getBundleInfo_2100 + * @tc.name testGetBundleInfoOtherUserIdPromise + * @tc.desc Test getBundleInfo interface with other userId (by promise). + */ + it('testGetBundleInfoOtherUserIdPromise', 0, async function (done) { + await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, { + userId: 1 + }).then(data => { + console.info("testGetBundleInfoOtherUserIdPromise success" + JSON.stringify(data)); + expect(data).assertFail(); + done(); + }).catch(err => { + console.info("testGetBundleInfoOtherUserIdPromise err" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + }); + }) + + /** + * @tc.number getBundleInfo_2200 + * @tc.name testGetBundleInfoOtherUserIdCallback + * @tc.desc Test getBundleInfo interface with other userId (by callback). + */ + it('testGetBundleInfoOtherUserIdCallback', 0, async function (done) { + await demo.getBundleInfo(NAME1, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, { + userId: 1 + }, (err, dataInfo) => { + if (err) { + console.info("testGetBundleInfoOtherUserIdCallback err" + JSON.stringify(err)); + expect(err).assertEqual(1); + done(); + return; + } + console.info("testGetBundleInfoOtherUserIdCallback success" + JSON.stringify(dataInfo)); + expect(dataInfo).assertFail(); + done(); + }); + }) + + /** + * @tc.number getApplicationInfos_0100 + * @tc.name testGetAllApplicationInfoPromise + * @tc.desc Test getApplicationInfos interfaces with one hap. + */ + it('testGetAllApplicationInfoPromise', 0, async function (done) { + let datainfo = await demo.getAllApplicationInfo(demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, userId); + checkgetApplicationInfos(datainfo); + done(); + }) + + function checkgetApplicationInfos(datainfo) { + console.log("=============datainfo.length===============" + datainfo.length); + expect(datainfo.length).assertLarger(0); + for (let i = 0; i < datainfo.length; i++) { + expect(datainfo[i].name.length).assertLarger(0); + if (datainfo[i].name == NAME1 || datainfo[i].name == NAME2 + || datainfo[i].name == NAME3 || datainfo[i].name == NAME4 || datainfo[i].name == NAME5) { + expect(datainfo[i].description.length >= 0).assertTrue(); + expect(datainfo[i].icon.length).assertLarger(0); + expect(datainfo[i].label.length).assertLarger(0); + } + expect(datainfo[i].moduleSourceDirs.length).assertLarger(0); + expect(datainfo[i].moduleInfos.length).assertLarger(0); + expect(datainfo[i].supportedModes).assertEqual(0); + for (let j = 0; j < datainfo[i].moduleInfos.length; j++) { + expect(datainfo[i].moduleInfos[j].moduleName.length).assertLarger(0); + expect(datainfo[i].moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + } + + } + + /** + * @tc.number getApplicationInfos_0600 + * @tc.name testGetAllApplicationInfoCallback + * @tc.desc Test getApplicationInfos interfaces with one hap. + */ + it('testGetAllApplicationInfoCallback', 0, async function (done) { + await demo.getAllApplicationInfo(demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId, (error, datainfo) => { + expect(datainfo.length).assertLarger(0); + for (let i = 0; i < datainfo.length; i++) { + expect(datainfo[i].name.length).assertLarger(0); + expect(datainfo[i].moduleSourceDirs.length).assertLarger(0); + expect(datainfo[i].moduleInfos.length).assertLarger(0); + expect(datainfo[i].supportedModes).assertEqual(0); + for (let j = 0; j < datainfo[i].moduleInfos.length; j++) { + expect(datainfo[i].moduleInfos[j].moduleName.length).assertLarger(0); + expect(datainfo[i].moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + } + done(); + }); + }) + + /** + * @tc.number getBundleInfos_0100 + * @tc.name testGetAllBundleInfoPromise + * @tc.desc Test getBundleInfos interfaces with one hap. + */ + it('testGetAllBundleInfoPromise', 0, async function (done) { + let data = await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT); + expect(typeof data).assertEqual(OBJECT); + expect(data.length).assertLarger(0); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + /** + * @tc.number getApplicationInfo_0100 + * @tc.name testGetApplicationInfoMetaDataPromise + * @tc.desc Test getApplicationInfo interfaces with one hap. (by promise) + */ + it('testGetApplicationInfoMetaDataPromise', 0, async function (done) { + await demo.getApplicationInfo(NAME1, + demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION | demo.BundleFlag.GET_APPLICATION_INFO_WITH_METADATA, + userId).then(datainfo => { + expect(typeof datainfo).assertEqual(OBJECT); + console.info("getApplicationInfo success:" + JSON.stringify(datainfo)); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertLarger(0); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.descriptionId).assertLarger(0); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.process).assertEqual(NAME1); + expect(datainfo.enabled).assertEqual(true); + expect(datainfo.metaData.entry[0].name).assertEqual("metaDataName"); + expect(datainfo.metaData.entry[0].value).assertEqual("metaDataValue"); + expect(datainfo.metaData.entry[0].extra).assertEqual("$string:app_name"); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + done(); + }).catch(err => { + console.info("getApplicationInfo fail:" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_0600 + * @tc.name testGetApplicationInfoMetaDataCallback + * @tc.desc Test getApplicationInfo interfaces with one hap. (by callback) + */ + it('testGetApplicationInfoMetaDataCallback', 0, async function (done) { + await demo.getApplicationInfo(NAME1, + demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION | demo.BundleFlag.GET_APPLICATION_INFO_WITH_METADATA, + userId, (error, datainfo) => { + if (error.code != 0) { + console.info("testGetApplicationInfoMetaDataCallback fail:" + JSON.stringify(error)); + expect(error).assertFail(); + done(); + return; + } + expect(typeof datainfo).assertEqual(OBJECT); + console.info("testGetApplicationInfoMetaDataCallback success:" + JSON.stringify(datainfo)); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertLarger(0); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.descriptionId).assertLarger(0); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.process).assertEqual(NAME1); + expect(datainfo.enabled).assertEqual(true); + expect(datainfo.metaData.entry[0].name).assertEqual("metaDataName"); + expect(datainfo.metaData.entry[0].value).assertEqual("metaDataValue"); + expect(datainfo.metaData.entry[0].extra).assertEqual("$string:app_name"); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_0200 + * @tc.name testGetApplicationInfoTwoHapPromise + * @tc.desc Test getApplicationInfo interfaces with two haps. (by promise) + */ + it('testGetApplicationInfoTwoHapPromise', 0, async function (done) { + let datainfo = await demo.getApplicationInfo(NAME2, + demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, userId); + console.info("testGetApplicationInfoTwoHapPromise result" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name.length).assertLarger(0); + expect(datainfo.description.length).assertLarger(0); + expect(datainfo.icon.length).assertLarger(0); + expect(datainfo.label.length).assertLarger(0); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertLarger(0); + expect(datainfo.name).assertEqual(NAME2); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(datainfo.iconId >= 0).assertTrue(); + expect(datainfo.labelId >= 0).assertTrue(); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.process).assertEqual(NAME2); + expect(datainfo.enabled).assertEqual(true); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertEqual(2); + expect(datainfo.moduleInfos[0].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[1].moduleName).assertEqual("feature"); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + done(); + }) + + /** + * @tc.number getApplicationInfo_0700 + * @tc.name testGetApplicationInfoTwoHapCallback + * @tc.desc Test getApplicationInfo interfaces with two haps. (by callback) + */ + it('testGetApplicationInfoTwoHapCallback', 0, async function (done) { + await demo.getApplicationInfo(NAME2, + demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, userId, (error, datainfo) => { + console.info("testGetApplicationInfoTwoHapCallback result" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name.length).assertLarger(0); + expect(datainfo.description.length).assertLarger(0); + expect(datainfo.icon.length).assertLarger(0); + expect(datainfo.label.length).assertLarger(0); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertLarger(0); + expect(datainfo.name).assertEqual(NAME2); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(datainfo.iconId >= 0).assertTrue(); + expect(datainfo.labelId >= 0).assertTrue(); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.process).assertEqual(NAME2); + expect(datainfo.enabled).assertEqual(true); + expect(datainfo.moduleSourceDirs.length).assertLarger(0); + expect(datainfo.moduleInfos.length).assertEqual(2); + expect(datainfo.moduleInfos[0].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[1].moduleName).assertEqual("feature"); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_0300 + * @tc.name testGetApplicationInfoThereHapPromise + * @tc.desc Test getApplicationInfo interfaces with three haps. (by promise) + */ + it('testGetApplicationInfoThereHapPromise', 0, async function (done) { + let datainfo = await demo.getApplicationInfo(NAME3, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId); + console.info("testGetApplicationInfoThereHapPromise result" + JSON.stringify(datainfo)); + expect(datainfo.name).assertEqual(NAME3); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.name).assertEqual(NAME3); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.iconId >= 0).assertTrue(); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.labelId >= 0).assertTrue(); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + done(); + }) + + /** + * @tc.number getApplicationInfo_2000 + * @tc.name testGetApplicationInfoThereHapCallback + * @tc.desc Test getApplicationInfo interfaces with three haps. (by callback) + */ + it('testGetApplicationInfoThereHapCallback', 0, async function (done) { + await demo.getApplicationInfo(NAME3, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId, (error, datainfo) => { + console.info("testGetApplicationInfoThereHapCallback result" + JSON.stringify(datainfo)); + expect(datainfo.name).assertEqual(NAME3); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.name).assertEqual(NAME3); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.iconId >= 0).assertTrue(); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.labelId >= 0).assertTrue(); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_0400 + * @tc.name testGetApplicationInfoNotExistCallback + * @tc.desc Test getApplicationInfo interfaces with error hap. (by promise) + */ + it('testGetApplicationInfoNotExistCallback', 0, async function (done) { + await demo.getApplicationInfo(ERROR, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId).then(datainfo => { + console.info("testGetApplicationInfoNotExistCallback success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }).catch(err => { + console.info("testGetApplicationInfoNotExistCallback err" + JSON.stringify(err)); + expect(err.code).assertEqual(1); + done(); + }); + }) + + /** + * @tc.number getApplicationInfo_0900 + * @tc.name testGetApplicationInfoNotExistPromise + * @tc.desc Test getApplicationInfo interfaces with error hap. (by callback) + */ + it('testGetApplicationInfoNotExistPromise', 0, async function (done) { + await demo.getApplicationInfo(ERROR, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId, (error, datainfo) => { + if (error) { + console.info("testGetApplicationInfoNotExistPromise fail" + JSON.stringify(error)); + expect(error.code).assertEqual(1); + done(); + return; + } + console.info("testGetApplicationInfoNotExistPromise success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_0500 + * @tc.name testGetApplicationInfoInvalidParamPromise + * @tc.desc Test getApplicationInfo interfaces with none hap. (by promise) + */ + it('testGetApplicationInfoInvalidParamPromise', 0, async function (done) { + await demo.getApplicationInfo('', demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId).then(datainfo => { + console.info("testGetApplicationInfoInvalidParamPromise success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }).catch(error => { + console.info("testGetApplicationInfoInvalidParamPromise err" + JSON.stringify(error)); + expect(error.code).assertEqual(1); + done(); + }); + }) + + /** + * @tc.number getApplicationInfo_1000 + * @tc.name testGetApplicationInfoInvalidParamCallback + * @tc.desc Test getApplicationInfo interfaces with none hap. (by callback) + */ + it('testGetApplicationInfoInvalidParamCallback', 0, async function (done) { + await demo.getApplicationInfo('', demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId, (error, datainfo) => { + if (error) { + console.info("testGetApplicationInfoInvalidParamCallback fail" + JSON.stringify(error)); + expect(error.code).assertEqual(1); + done(); + return; + } + console.info("testGetApplicationInfoInvalidParamCallback success" + JSON.stringify(datainfo)); + expect(datainfo).assertFail(); + done(); + }); + }) + + /** + * @tc.number getApplicationInfo_1100 + * @tc.name testGetApplicationInfoDifferentParamPromise + * @tc.desc Test getApplicationInfo interfaces with one hap and different param. (by promise) + */ + it('testGetApplicationInfoDifferentParamPromise', 0, async function (done) { + await demo.getApplicationInfo(NAME1, demo.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(datainfo => { + console.info("getApplicationInfo_1100 success" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.descriptionId).assertLarger(0); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + done(); + }).catch(err => { + console.info("testGetApplicationInfoDifferentParamPromise fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_1200 + * @tc.name testGetApplicationInfoDifferentParamCallback + * @tc.desc Test getApplicationInfo interfaces with one hap and different param. (by callback) + */ + it('testGetApplicationInfoDifferentParamCallback', 0, async function (done) { + await demo.getApplicationInfo(NAME1, demo.BundleFlag.GET_BUNDLE_DEFAULT, userId, (error, datainfo) => { + if (error.code != 0) { + console.info("testGetApplicationInfoDifferentParamCallback fail" + JSON.stringify(error)); + expect(error).assertFail(); + done(); + return; + } + console.info("testGetApplicationInfoDifferentParamCallback success" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.descriptionId).assertLarger(0); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_1300 + * @tc.name testGetApplicationInfoPromise + * @tc.desc Test getApplicationInfo interfaces with one hap. (by promise) + */ + it('testGetApplicationInfoPromise', 0, async function (done) { + await demo.getApplicationInfo(NAME1, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId).then(datainfo => { + console.info("testGetApplicationInfoPromise success:" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.enabled).assertEqual(true); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + done(); + }).catch(error => { + console.info("testGetApplicationInfoPromise fail:" + JSON.stringify(error)); + expect(error).assertFail(); + done(); + }) + }) + + /** + * @tc.number getApplicationInfo_1400 + * @tc.name testGetApplicationInfoCallback + * @tc.desc Test getApplicationInfo interfaces with one hap. (by callback) + */ + it('testGetApplicationInfoCallback', 0, async function (done) { + await demo.getApplicationInfo(NAME1, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, userId, + (error, datainfo) => { + if (error.code != 0) { + console.info("testGetApplicationInfoCallback fail:" + JSON.stringify(error)); + expect(error).assertFail(); + done(); + return; + } + console.info("testGetApplicationInfoCallback success:" + JSON.stringify(datainfo)); + expect(typeof datainfo).assertEqual(OBJECT); + expect(datainfo.name).assertEqual(NAME1); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.descriptionId >= 0).assertTrue(); + expect(parseInt(datainfo.iconId)).assertLarger(0); + expect(parseInt(datainfo.labelId)).assertLarger(0); + expect(datainfo.systemApp).assertEqual(false); + expect(datainfo.supportedModes).assertEqual(0); + expect(datainfo.enabled).assertEqual(true); + for (let j = 0; j < datainfo.moduleInfos.length; j++) { + expect(datainfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + done(); + }) + }) + + /** + * @tc.number getBundleInfos_0600 + * @tc.name testGetAllBundleInfoCallback + * @tc.desc Test getBundleInfos interfaces with one hap. + */ + it('testGetAllBundleInfoCallback', 0, async function (done) { + await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, (error, data) => { + expect(typeof data).assertEqual(OBJECT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }); + }) + + /** + * @tc.number getApplicationInfos_0200 + * @tc.name testGetAllApplicationInfoTwoHapPromise + * @tc.desc Test getApplicationInfos interfaces with two haps. + */ + it('testGetAllApplicationInfoTwoHapPromise', 0, async function (done) { + let datainfo = await demo.getAllApplicationInfo(demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, userId); + console.info("==========ActsBmsGetInfosSecondScene is ==========" + JSON.stringify(datainfo)); + checkgetApplicationInfos(datainfo); + done(); + }) + + /** + * @tc.number getApplicationInfos_0400 + * @tc.name testGetAllApplicationInfoDifferentParamPromise + * @tc.desc Test getApplicationInfos interfaces with two haps and different param. + */ + it('testGetAllApplicationInfoDifferentParamPromise', 0, async function (done) { + let datainfo = await demo.getAllApplicationInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, userId); + expect(datainfo.length).assertLarger(0); + checkgetApplicationInfos(datainfo); + done(); + }) + + /** + * @tc.number getApplicationInfos_0700 + * @tc.name testGetAllApplicationInfoTwoHapCallback + * @tc.desc Test getApplicationInfos interfaces with two haps. + */ + it('testGetAllApplicationInfoTwoHapCallback', 0, async function (done) { + await demo.getAllApplicationInfo(demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + userId, (error, datainfo) => { + for (let i = 0; i < datainfo.length; i++) { + expect(datainfo[i].name.length).assertLarger(0); + if (datainfo[i].name == NAME1 || datainfo[i].name == NAME2 + || datainfo[i].name == NAME3 || datainfo[i].name == NAME4 || datainfo[i].name == NAME5) { + expect(datainfo[i].description.length >= 0).assertTrue(); + expect(datainfo[i].icon.length).assertLarger(0); + expect(datainfo[i].label.length).assertLarger(0); + } + expect(datainfo[i].moduleSourceDirs.length).assertLarger(0); + expect(datainfo[i].moduleInfos.length).assertLarger(0); + expect(datainfo[i].supportedModes).assertEqual(0); + for (let j = 0; j < datainfo[i].moduleInfos.length; j++) { + expect(datainfo[i].moduleInfos[j].moduleName.length).assertLarger(0); + expect(datainfo[i].moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + } + done(); + }); + }) + + /** + * @tc.number getApplicationInfos_0800 + * @tc.name testGetAllApplicationInfoThereHapCallback + * @tc.desc Test getApplicationInfos interfaces with three haps. + */ + it('testGetAllApplicationInfoThereHapCallback', 0, async function (done) { + await demo.getAllApplicationInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, userId, (error, datainfo) => { + for (let i = 0; i < datainfo.length; i++) { + expect(datainfo[i].name.length).assertLarger(0); + if (datainfo[i].name == NAME1 || datainfo[i].name == NAME2 + || datainfo[i].name == NAME3 || datainfo[i].name == NAME4 || datainfo[i].name == NAME5) { + expect(datainfo[i].description.length >= 0).assertTrue(); + expect(datainfo[i].icon.length).assertLarger(0); + expect(datainfo[i].label.length).assertLarger(0); + } + expect(datainfo[i].moduleSourceDirs.length).assertLarger(0); + expect(datainfo[i].moduleInfos.length).assertLarger(0); + expect(datainfo[i].supportedModes).assertEqual(0); + for (let j = 0; j < datainfo[i].moduleInfos.length; j++) { + expect(datainfo[i].moduleInfos[j].moduleName.length).assertLarger(0); + expect(datainfo[i].moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + } + done(); + }); + }) + + /** + * @tc.number getApplicationInfos_0900 + * @tc.name testGetAllApplicationInfoDifferentParamCallback + * @tc.desc Test getApplicationInfos interfaces with two haps and different param. + */ + it('testGetAllApplicationInfoDifferentParamCallback', 0, async function (done) { + await demo.getAllApplicationInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, userId, (error, datainfo) => { + for (let i = 0; i < datainfo.length; i++) { + expect(datainfo[i].name.length).assertLarger(0); + if (datainfo[i].name == NAME1 || datainfo[i].name == NAME2 + || datainfo[i].name == NAME3 || datainfo[i].name == NAME4 || datainfo[i].name == NAME5) { + expect(datainfo[i].description.length >= 0).assertTrue(); + expect(datainfo[i].icon.length).assertLarger(0); + expect(datainfo[i].label.length).assertLarger(0); + } + expect(datainfo[i].moduleSourceDirs.length).assertLarger(0); + expect(datainfo[i].moduleInfos.length).assertLarger(0); + expect(datainfo[i].supportedModes).assertEqual(0); + for (let j = 0; j < datainfo[i].moduleInfos.length; j++) { + expect(datainfo[i].moduleInfos[j].moduleName.length).assertLarger(0); + expect(datainfo[i].moduleInfos[j].moduleSourceDir.length).assertLarger(0); + } + } + done(); + }); + }) + + /** + * @tc.number getBundleInfos_0200 + * @tc.name testGetAllBundleInfoTwoHapPromise + * @tc.desc Test getBundleInfos interfaces with two haps. + */ + it('testGetAllBundleInfoTwoHapPromise', 0, async function (done) { + let data = await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT); + expect(typeof data).assertEqual(OBJECT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + /** + * @tc.number getBundleInfos_0400 + * @tc.name testGetAllBundleInfoTwoHapDifferentParamPromise + * @tc.desc Test getBundleInfos interfaces with two haps and different param. + */ + it('testGetAllBundleInfoTwoHapDifferentParamPromise', 0, async function (done) { + let data = await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + expect(typeof data).assertEqual(OBJECT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + + /** + * @tc.number getBundleInfos_0700 + * @tc.name testGetAllBundleInfoTwoHapCallback + * @tc.desc Test getBundleInfos interfaces with two haps. + */ + it('testGetAllBundleInfoTwoHapCallback', 0, async function (done) { + await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, (error, data) => { + expect(typeof data).assertEqual(OBJECT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + }) + + /** + * @tc.number getBundleInfos_0900 + * @tc.name testGetAllBundleInfoTwoHapDifferentParamCallback + * @tc.desc Test getBundleInfos interfaces with two haps and different param. + */ + it('testGetAllBundleInfoTwoHapDifferentParamCallback', 0, async function (done) { + await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, (error, data) => { + expect(typeof data).assertEqual(OBJECT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + }) + + /** + * @tc.number getBundleInfos_0300 + * @tc.name testGetAllBundleInfoThereHapPromise + * @tc.desc Test getBundleInfos interfaces with three haps. + */ + it('testGetAllBundleInfoThereHapPromise', 0, async function (done) { + let data = await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + /** + * @tc.number getBundleInfos_0500 + * @tc.name testGetAllBundleInfoThereHapDifferentParamPromise + * @tc.desc Test getBundleInfos interfaces with three haps and different param. + */ + it('testGetAllBundleInfoThereHapDifferentParamPromise', 0, async function (done) { + let data = await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + /** + * @tc.number getBundleInfos_0800 + * @tc.name testGetAllBundleInfoThereHapCallback + * @tc.desc Test getBundleInfos interfaces with three haps. + */ + it('testGetAllBundleInfoThereHapCallback', 0, async function (done) { + await demo.getAllBundleInfo(demo.BundleFlag.GET_BUNDLE_DEFAULT, (error, data) => { + for (let i = 0; i < data.length; i++) { + expect(data[i].name.length).assertLarger(0); + expect(data[i].appInfo.name.length).assertLarger(0); + if (data[i].name == NAME1 || data[i].name == NAME2 + || data[i].name == NAME3 || data[i].name == NAME4 || data[i].name == NAME5) { + expect(data[i].appInfo.description.length >= 0).assertTrue(); + expect(data[i].appInfo.icon.length).assertLarger(0); + expect(data[i].appInfo.label.length).assertLarger(0); + } + expect(data[i].appInfo.supportedModes).assertEqual(0); + expect(data[i].appInfo.moduleInfos.length).assertLarger(0); + } + done(); + }) + + }) + + /** + * @tc.number queryAbilityByWant_0100 + * @tc.name testQueryAbilityByWantPromise + * @tc.desc Test queryAbilityByWant interfaces with none hap. (by promise) + */ + it('testQueryAbilityByWantPromise', 0, async function (done) { + await demo.queryAbilityByWant( + { + "bundleName": "com.example.myapplication1", + "abilityName": "com.example.myapplication1.MainAbility", + }, demo.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION | + demo.BundleFlag.GET_ABILITY_INFO_WITH_PERMISSION | + demo.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, + userId).then(data => { + expect(data.length).assertLarger(0); + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantPromise success:" + JSON.stringify(datainfo)); + expect(datainfo.name).assertEqual("com.example.myapplication1.MainAbility"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME1); + expect(datainfo.type).assertEqual(demo.AbilityType.PAGE); + expect(datainfo.subType).assertEqual(demo.AbilitySubType.UNSPECIFIED); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.UNSPECIFIED); + expect(datainfo.launchMode).assertEqual(demo.LaunchMode.STANDARD); + expect(datainfo.permissions[0]).assertEqual("com.permission.BMS_PERMISSION_CAMERA"); + expect(datainfo.applicationInfo.name).assertEqual(NAME1); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + expect(datainfo.metaData.length).assertLarger(0); + for (let j = 0; j < datainfo.applicationInfo.moduleInfos.length; j++) { + expect(datainfo.applicationInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.applicationInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + } + done(); + }).catch(err => { + console.info("testQueryAbilityByWantPromise err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_0500 + * @tc.name testQueryAbilityByWantCallback + * @tc.desc Test queryAbilityByWant interfaces with none hap. (by callback) + */ + it('testQueryAbilityByWantCallback', 0, async function (done) { + demo.queryAbilityByWant( + { + "bundleName": "com.example.myapplication1", + "abilityName": "com.example.myapplication1.MainAbility", + }, demo.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION | + demo.BundleFlag.GET_ABILITY_INFO_WITH_PERMISSION | + demo.BundleFlag.GET_ABILITY_INFO_WITH_METADATA, + userId, (err, data) => { + if (err) { + console.info("testQueryAbilityByWantCallback err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + return; + } + expect(data.length).assertLarger(0); + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantCallback success:" + JSON.stringify(datainfo)); + expect(datainfo.name).assertEqual("com.example.myapplication1.MainAbility"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME1); + expect(datainfo.type).assertEqual(demo.AbilityType.PAGE); + expect(datainfo.subType).assertEqual(demo.AbilitySubType.UNSPECIFIED); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.UNSPECIFIED); + expect(datainfo.launchMode).assertEqual(demo.LaunchMode.STANDARD); + expect(datainfo.permissions[0]).assertEqual("com.permission.BMS_PERMISSION_CAMERA"); + expect(datainfo.applicationInfo.name).assertEqual(NAME1); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + expect(datainfo.metaData.length).assertLarger(0); + for (let j = 0; j < datainfo.applicationInfo.moduleInfos.length; j++) { + expect(datainfo.applicationInfo.moduleInfos[j].moduleName).assertEqual("entry"); + expect(datainfo.applicationInfo.moduleInfos[j].moduleSourceDir).assertEqual(DIR1); + } + } + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_0200 + * @tc.name testQueryAbilityByWantTwoHapPromise + * @tc.desc Test queryAbilityByWant interfaces with two haps. (by promise) + */ + it('testQueryAbilityByWantTwoHapPromise', 0, async function (done) { + let data = await demo.queryAbilityByWant( + { + "bundleName": "com.example.myapplication2", + "abilityName": "com.example.myapplication1.MainAbility", + }, demo.BundleFlag.GET_ALL_APPLICATION_INFO, userId); + expect(data.length).assertLarger(0); + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantTwoHapPromise success:" + JSON.stringify(datainfo)); + expect(datainfo.name.length).assertLarger(0); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME2); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.LANDSCAPE); + expect(datainfo.launchMode).assertEqual(demo.LaunchMode.SINGLETON); + expect(datainfo.applicationInfo.name).assertEqual(NAME2); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + expect(datainfo.applicationInfo.moduleInfos[0].moduleName).assertEqual("entry"); + expect(datainfo.applicationInfo.moduleInfos[0].moduleSourceDir).assertEqual(DIR3); + expect(datainfo.applicationInfo.moduleInfos[1].moduleName).assertEqual("feature"); + expect(datainfo.applicationInfo.moduleInfos[1].moduleSourceDir).assertEqual(DIR2); + } + done(); + }) + + /** + * @tc.number queryAbilityByWant_0600 + * @tc.name testQueryAbilityByWantTwoHapCallback + * @tc.desc Test queryAbilityByWant interfaces with two haps. (by callback) + */ + it('testQueryAbilityByWantTwoHapCallback', 0, async function (done) { + await demo.queryAbilityByWant( + { + "bundleName": "com.example.myapplication2", + "abilityName": "com.example.myapplication1.MainAbility", + }, demo.BundleFlag.GET_ALL_APPLICATION_INFO, userId, (error, data) => { + expect(data.length).assertLarger(0); + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantTwoHapCallback success:" + JSON.stringify(datainfo)); + expect(datainfo.name.length).assertLarger(0); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME2); + expect(datainfo.orientation).assertEqual(1); + expect(datainfo.launchMode).assertEqual(demo.LaunchMode.SINGLETON); + expect(datainfo.applicationInfo.name).assertEqual(NAME2); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + expect(datainfo.applicationInfo.moduleInfos[0].moduleName).assertEqual("entry"); + expect(datainfo.applicationInfo.moduleInfos[0].moduleSourceDir).assertEqual(DIR3); + expect(datainfo.applicationInfo.moduleInfos[1].moduleName).assertEqual("feature"); + expect(datainfo.applicationInfo.moduleInfos[1].moduleSourceDir).assertEqual(DIR2); + } + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_0300 + * @tc.name testQueryAbilityByWantThereHapPromise + * @tc.desc Test queryAbilityByWant interfaces with three haps. (by promise) + */ + it('testQueryAbilityByWantThereHapPromise', 0, async function (done) { + await demo.queryAbilityByWant({ + entities: ['entity.system.home', 'entitiesentities'] + }, 4, userId).then(data => { + checkAbilityInfo0500(data) + done(); + }).catch(err => { + console.info("testQueryAbilityByWantThereHapPromise err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + }) + + function checkAbilityInfo0500(data) { + let queryResultCount = 0; + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantThereHapPromise success:" + JSON.stringify(datainfo)); + if (datainfo.bundleName == NAME3) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME3); + expect(datainfo.type).assertEqual(demo.AbilityType.PAGE); + expect(datainfo.applicationInfo.name).assertEqual(NAME3); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.PORTRAIT); + expect(datainfo.orientation).assertEqual(2); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + for (let j = 0; j < datainfo.applicationInfo.moduleInfos.length; j++) { + expect(datainfo.applicationInfo.moduleInfos[j].moduleName).assertEqual("entry"); + } + queryResultCount++; + } + if (datainfo.bundleName == NAME4) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.type).assertEqual(demo.AbilityType.DATA); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.UNSPECIFIED); + expect(datainfo.bundleName).assertEqual(NAME4); + queryResultCount++; + } + if (datainfo.bundleName == NAME5) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.type).assertEqual(demo.AbilityType.PAGE); + expect(datainfo.bundleName).assertEqual(NAME5); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.FOLLOW_RECENT); + queryResultCount++; + } + } + expect(queryResultCount).assertEqual(3); + } + + /** + * @tc.number queryAbilityByWant_0700 + * @tc.name testQueryAbilityByWantThereHapCallback + * @tc.desc Test queryAbilityByWant interfaces with three haps. (by callback) + */ + it('testQueryAbilityByWantThereHapCallback', 0, async function (done) { + await demo.queryAbilityByWant( + { + entities: ['entity.system.home', 'entitiesentities'] + }, 4, userId, (err, data) => { + if (err) { + console.info("testQueryAbilityByWantThereHapCallback err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + return; + } + checkAbilityInfo0600(data); + done(); + }) + }) + + function checkAbilityInfo0600(data) { + let queryResultCount = 0; + for (let i = 0, len = data.length; i < len; i++) { + let datainfo = data[i]; + console.info("testQueryAbilityByWantThereHapCallback success:" + JSON.stringify(datainfo)); + if (datainfo.bundleName == NAME3) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.label).assertEqual("$string:app_name"); + expect(datainfo.description).assertEqual(DESCRIPTION); + expect(datainfo.icon).assertEqual("$media:icon"); + expect(datainfo.moduleName).assertEqual("entry"); + expect(datainfo.bundleName).assertEqual(NAME3); + expect(datainfo.applicationInfo.name).assertEqual(NAME3); + expect(datainfo.applicationInfo.description).assertEqual(APPLICATION_DESCRIPTION); + expect(datainfo.applicationInfo.descriptionId >= 0).assertTrue(); + expect(datainfo.applicationInfo.icon).assertEqual("$media:icon"); + expect(datainfo.applicationInfo.iconId >= 0).assertTrue(); + expect(datainfo.applicationInfo.label).assertEqual("$string:app_name"); + expect(datainfo.applicationInfo.labelId >= 0).assertTrue(); + expect(datainfo.applicationInfo.systemApp).assertEqual(false); + expect(datainfo.applicationInfo.supportedModes).assertEqual(0); + expect(datainfo.orientation).assertEqual(2); + expect(datainfo.applicationInfo.enabled).assertEqual(true); + for (let j = 0; j < datainfo.applicationInfo.moduleInfos.length; j++) { + expect(datainfo.applicationInfo.moduleInfos[j].moduleName).assertEqual("entry"); + } + queryResultCount++; + } + if (datainfo.bundleName == NAME4) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.bundleName).assertEqual(NAME4); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.UNSPECIFIED); + queryResultCount++; + } + if (datainfo.bundleName == NAME5) { + expect(datainfo.name).assertEqual("com.example.myapplication.MainAbility"); + expect(datainfo.bundleName).assertEqual(NAME5); + expect(datainfo.orientation).assertEqual(demo.DisplayOrientation.FOLLOW_RECENT); + queryResultCount++; + } + } + expect(queryResultCount).assertEqual(3); + } + + /** + * @tc.number queryAbilityByWant_0800 + * @tc.name testQueryAbilityByWantNotExistHapPromise + * @tc.desc Test queryAbilityByWant interfaces with one hap. (by promise) + */ + it('testQueryAbilityByWantNotExistHapPromise', 0, async function (done) { + await demo.queryAbilityByWant( + { + "bundleName": "wrong name", + "abilityName": "com.example.myapplication1.MainAbility" + }, demo.BundleFlag.GET_BUNDLE_DEFAULT, userId).then(datainfo => { + console.info("testQueryAbilityByWantNotExistHapPromise dataInfo : ===========" + datainfo); + expect(datainfo).assertFail(); + done(); + }).catch(err => { + console.info("testQueryAbilityByWantNotExistHapPromise err : ===========" + err); + expect(err).assertEqual(1); + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_0900 + * @tc.name testQueryAbilityByWantNotExistHapCallback + * @tc.desc Test queryAbilityByWant interfaces with one hap. (by callback) + */ + it('testQueryAbilityByWantNotExistHapCallback', 0, async function (done) { + await demo.queryAbilityByWant( + { + "bundleName": "wrong name", + "abilityName": "com.example.myapplication1.MainAbility" + }, demo.BundleFlag.GET_BUNDLE_DEFAULT, userId, (err, datainfo) => { + if (err) { + console.info("testQueryAbilityByWantNotExistHapCallback err : ===========" + err); + expect(err).assertEqual(1); + done(); + return; + } + console.info("testQueryAbilityByWantNotExistHapCallback dataInfo : ===========" + datainfo); + expect(datainfo).assertFail(); + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_0400 + * @tc.name testQueryAbilityByWantSystemHapPromise + * @tc.desc Test queryAbilityByWant interfaces with system hap. (by promise) + */ + it('testQueryAbilityByWantSystemHapPromise', 0, async function (done) { + await demo.queryAbilityByWant( + { + bundleName: "wrong name", + abilityName: "wrong name", + }, 0, userId).then(datainfo => { + console.info("testQueryAbilityByWantSystemHapPromise dataInfo : ===========" + datainfo); + expect(datainfo.length).assertLarger(0); + done(); + }).catch(err => { + console.info("testQueryAbilityByWantSystemHapPromise err : ===========" + err); + expect(err).assertEqual(1); + done(); + }) + }) + + /** + * @tc.number queryAbilityByWant_1100 + * @tc.name testQueryAbilityByWantSystemHapCallback + * @tc.desc Test queryAbilityByWant interfaces with system hap. (by callback) + */ + it('testQueryAbilityByWantSystemHapCallback', 0, async function (done) { + demo.queryAbilityByWant( + { + bundleName: "wrong name", + abilityName: "wrong name", + }, 0, userId, OnReceiveEvent); + + function OnReceiveEvent(err, datainfo) { + console.info("testQueryAbilityByWantSystemHapCallback err : ===========" + err); + console.info("testQueryAbilityByWantSystemHapCallback dataInfo : ===========" + datainfo); + expect(err).assertEqual(1); + expect(datainfo.length).assertLarger(0); + done(); + } + }) + /** * @tc.number installErrCodeTest_0100 * @tc.name InstallErrorCode::STATUS_FAILED_NO_SPACE_LEFT