diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/BUILD.gn b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..90f40cc40ac493a464a10ca593a6c971ab72e21b --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/BUILD.gn @@ -0,0 +1,31 @@ +# 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("ActsStServiceAbilityClientCaseTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsStServiceAbilityClientCaseTest" +} +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "./entry/src/main/js/default" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./entry/src/main/js/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/Test.json b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..cd03f2a6b0adfe4da3313dcd27edf49060484d4e --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "com.amsst.actsstserviceabilityclientcasetest", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsStServiceAbilityClientCaseTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/config.json b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a969be745a7aba3a3b3a4b1da5ba0c9befde3237 --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/config.json @@ -0,0 +1,91 @@ +{ + "app": { + "bundleName": "com.amsst.actsstserviceabilityclientcasetest", + "vendor": "amsst", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.amsst.actsstserviceabilityclientcasetest", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.amsst.actsstserviceabilityclientcasetest.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.INSTALL_BUNDLE", + "reason": "need use ohos.permission.INSTALL_BUNDLE" + }, + { + "name":"ohos.permission.GET_BUNDLE_INFO", + "reason":"need use ohos.permission.GET_BUNDLE_INFO" + }, + { + "name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"need use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name":"ohos.permission.CHANGE_ABILITY_ENABLED_STATE", + "reason":"need use ohos.permission.CHANGE_ABILITY_ENABLED_STATE" + }, + { + "name":"ohos.permission.REMOVE_CACHE_FILES", + "reason":"need use ohos.permission.REMOVE_CACHE_FILES" + }, + { + "name":"ohos.permission.LISTEN_BUNDLE_CHANGE", + "reason":"need use ohos.permission.LISTEN_BUNDLE_CHANGE" + }, + { + "name":"ohos.permission.MANAGE_LOCAL_ACCOUNTS", + "reason":"need use ohos.permission.MANAGE_LOCAL_ACCOUNTS" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/app.js b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..c158442201abb1888ae8fb1d57f150c5ec26c36b --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/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/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/en-US.json b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/zh-CN.json b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.css b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..ac39915c295d19be6b0c23ae374d30b8f13bc066 --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,12 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} +.titleST { + font-size: 32px; +} diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.hml b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..22cf7f2cc551020b093687fa5c15d59fd308de59 --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,8 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + + + StServiceAbilityClient + +
diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.js b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4bfa4f7e4a4085d7336a97befffb8d52882d281d --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,44 @@ +/* + * 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 file from '@system.file' +import app from '@system.app' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('====onShow finish====<') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/element/string.json b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a3d6946ded2ae6c810549377cc0c386ad257eb53 --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "StSeAbClient" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/media/icon.png b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/resources/base/media/icon.png differ diff --git a/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/test/ActsStServiceAbilityClientCaseTest.test.js b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/test/ActsStServiceAbilityClientCaseTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b9cb39c2f543089078e9c37caf4d86f26540cdf4 --- /dev/null +++ b/aafwk/aafwk_standard/ActsStServiceAbilityClientCaseTest/entry/src/main/js/test/ActsStServiceAbilityClientCaseTest.test.js @@ -0,0 +1,329 @@ +/* + * 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 featureAbility from '@ohos.ability.featureAbility' +import abilityManager from '@ohos.app.abilityManager' + +import commonEvent from '@ohos.commonevent' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' + +describe('ActsStServiceAbilityTest', function () { + let bundleName = "com.amsst.stserviceabilityserver"; + let abilityName = "com.amsst.stserviceabilityserver.ServiceAbility"; + + var subscriber0100; + var CommonEventSubscribeInfo0100 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0100", + ], + }; + var subscriber0200; + var CommonEventSubscribeInfo0200 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0200", + ], + }; + var subscriber0300; + var CommonEventSubscribeInfo0300 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0300", + "ACTS_SerivceAbilityServer_onCommand_PageStartService_0301", + ], + }; + var subscriber0400; + var CommonEventSubscribeInfo0400 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0400", + "ACTS_SerivceAbilityServer_onCommand_PageStartService_0401", + ], + }; + var subscriber0500; + var CommonEventSubscribeInfo0500 = { + events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; + var subscriber0600; + var CommonEventSubscribeInfo0600 = { + events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; + var subscriber0900; + var CommonEventSubscribeInfo0900 = { + events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900", + ], + }; + var subscriber1000; + var CommonEventSubscribeInfo1000 = { + events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000", + ], + }; + var subscriber1300; + var CommonEventSubscribeInfo1300 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300", + "ACTS_SerivceAbilityServerSecond_onDisConnect", + ], + }; + var subscriber1400; + var CommonEventSubscribeInfo1400 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400", + "ACTS_SerivceAbilityServerSecond_onDisConnect", + ], + }; + var subscriber1500; + var CommonEventSubscribeInfo1500 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; + + function unsubscribe(caller, subscriber) { + commonEvent.unsubscribe(subscriber, (err, data) => { + console.debug("=ACTS_unsubscribe (err,data)=======>" + + (caller) + + (" , json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + }); + } + let gSetTimeout = 1000 + beforeAll(async (done) => { + console.debug('= ACTS_beforeAll 1127 ==== { + setTimeout(function () { + done(); + }, gSetTimeout); + }) + afterEach(async (done) => { + setTimeout(function () { + done(); + }, gSetTimeout); + }) + afterAll((done) => { + console.debug('= ACTS_afterAll ===={ + console.log('ACTS_AbilityStartSetting_0100 asyncCallback errCode : ' + JSON.stringify(err) + + " data: " + JSON.stringify(data)); + expect(2097152).assertEqual(err.code); + done(); + }); + }catch(error){ + console.log("ACTS_AbilityStartSetting_0100 : error = " + error); + done(); + } + }) + + /* + * @tc.number: ACTS_JsServiceAbility_0600 + * @tc.name: featureAbility.ConnectAbility : Connects an ability to a Service ability. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + */ + it('ACTS_JsServiceAbility_0600', 0, async function (done) { + console.log('ACTS_JsServiceAbility_0600==== { + console.debug("=ACTS_JsServiceAbility_0600 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber0600 = data; + await commonEvent.subscribe(subscriber0600, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0600 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { + expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600").assertEqual( + data.event); + featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { + console.debug("=ACTS_JsServiceAbility_0600 disconnectAbility err====>" + + ("json err=") + JSON.stringify(err)); + }) + } else { + clearTimeout(currentAlertTimeout); + expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0600_unsubscribe", subscriber0600); + console.log('ACTS_JsServiceAbility_0600==== mConnIdJsAsyncCallback=' + + JSON.stringify(mConnIdJsAsyncCallback) + " , " + mConnIdJsAsyncCallback); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_0600_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_JsServiceAbility_0600_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + expect(code==featureAbility.ErrorCode.ABILITY_NOT_FOUND + || (code!=featureAbility.ErrorCode.NO_ERROR + || code!=featureAbility.ErrorCode.INVALID_PARAMETER + || code!=featureAbility.ErrorCode.PERMISSION_DENY + )).assertTrue(); + } + + mConnIdJsAsyncCallback = featureAbility.connectAbility( + { + bundleName: bundleName, + abilityName: abilityName, + action: "PageConnectService_0600", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + currentAlertTimeout = setTimeout(mySetTimeout, gSetTimeout); + function mySetTimeout() { + console.log('ACTS_JsServiceAbility_1400==== { + console.debug("=ACTS_JsServiceAbility_1400 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber1400 = data; + await commonEvent.subscribe(subscriber1400, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_1400 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") { + expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400" + ).assertEqual(data.event); + featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { + console.debug("=ACTS_JsServiceAbility_1400 disconnectAbility err====>" + + ("json err=") + JSON.stringify(err)); + }) + } else { + clearTimeout(currentAlertTimeout); + expect("ACTS_SerivceAbilityServerSecond_onDisConnect").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_1400_unsubscribe", subscriber1400); + console.log('ACTS_JsServiceAbility_1400==== mConnIdJsAsyncCallback=' + + JSON.stringify(mConnIdJsAsyncCallback) + " , " + mConnIdJsAsyncCallback); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_1400_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_JsServiceAbility_1400_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } + + mConnIdJsAsyncCallback = featureAbility.connectAbility( + { + bundleName: bundleName, + abilityName: abilityName, + action: "ServiceConnectService_1400", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + + currentAlertTimeout = setTimeout(mySetTimeout, gSetTimeout); + function mySetTimeout() { + console.log('ACTS_JsServiceAbility_1400====