diff --git a/ability/ability_runtime/BUILD.gn b/ability/ability_runtime/BUILD.gn index fc90f4a74a019873d9b54a7cc4c8b133352de7c9..11f2b5b68c741f43dbb3bd4669f9b4acfad289af 100644 --- a/ability/ability_runtime/BUILD.gn +++ b/ability/ability_runtime/BUILD.gn @@ -30,6 +30,7 @@ group("ability_runtime") { "actsdataabilityaccessdatasharetest:dataabilityaccessdatashare", "actsfwkdataaccessortest:dataability", "actsqueryfunctiontest:actsqueryfunctiontest", + "actsrequestdialogtest:actsrequestdialogtest", "actsserviceabilityclienttest:serviceability", "actsshellcommandfunctionalitytest:actsshellcommandfunctionalitytest", "actsstartrunnertest:ActsStartRunnerTest", diff --git a/ability/ability_runtime/actsrequestdialogtest/BUILD.gn b/ability/ability_runtime/actsrequestdialogtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c6098c73fdf804e9a4846e1d90bf51b8f29465c3 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +group("actsrequestdialogtest") { + testonly = true + if (is_standard_system) { + deps = [ "actsrequestdialog:ActsRequestDialogTest" ] + } +} diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/app.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..bbc803a387fd2380f42fed006a0fd0b3603817d7 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"com.acts.example.requestdialog", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:app_name", + "description":"$string:description_application", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":9, + "targetAPIVersion":9, + "car":{ + "apiCompatibleVersion":9, + "singleUser":false + } + } +} diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/BUILD.gn b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d643c0270206ae82da10191dbc4b61602da0d106 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/BUILD.gn @@ -0,0 +1,44 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsRequestDialogTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":actsrequestdialog_js_assets", + ":actsrequestrecent_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsRequestDialogTest" + + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsrequestdialog_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsrequestdialog_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("actsrequestrecent_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":actsrequestdialog_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/Test.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..08a8904ac3d01c44a1b32ae18f9dd6f04a610df8 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/Test.json @@ -0,0 +1,39 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.example.requestdialog", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [ + { + "test-file-name": [ + "ActsRequestDialogTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/test" + ] + }, + { + "type": "PushKit", + "push": [ + "ActsRequestDialogTest.hap->/data/test/ActsRequestDialogTest.hap" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "chmod 644 /data/test/*.hap" + ] + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/Application/AbilityStage.ts b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..08ad8c28ef9b03eea00f55fcee2dddfe75535278 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * 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 AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("MyAbilityStage onCreate"); + globalThis.stageContext = this.context; + } +} diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..17cd974c328bca5cc4d2fba8995bedf05db23fcf --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,64 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("MainAbility onCreate"); + globalThis.abilityWant = want; + globalThis.abilityContext = this.context; + globalThis.applicationContext = this.context.getApplicationContext(); + globalThis.requestDialogSuccess = false; + globalThis.validRequestInfo = false; + globalThis.validRequestCallback = false; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("MainAbility onDestroy"); + globalThis.applicationContext.killAllProcesses().then((data)=>{ + console.log(`MainAbility getRunningProcessInformation data ${JSON.stringify(data)}`); + }).catch((err)=>{ + console.log(`MainAbility getRunningProcessInformation err ${JSON.stringify(err)}`); + }) + + globalThis.applicationContext.killAllProcesses((err, data)=>{ + console.log(`MainAbility getRunningProcessInformation data ${JSON.stringify(data)} + err: ${JSON.stringify(err)}`); + }) + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("MainAbility onWindowStageCreate"); + windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log("MainAbility onWindowStageDestroy"); + } + + onForeground() { + // Ability has brought to foreground + console.log("MainAbility onForeground"); + } + + onBackground() { + // Ability has back to background + console.log("MainAbility onBackground"); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/index/index.ets b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..102626507c52819532978509d89bd74837367ee8 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -0,0 +1,58 @@ +/* + * 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 router from '@ohos.router'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../../test/List.test' +var testTime = 0; + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + if(testTime++==0){ + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/second/second.ets b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9009a3e8567d1f4557ebc11dded54c7e27c0b0d --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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 router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility2/MainAbility2.ts b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility2/MainAbility2.ts new file mode 100644 index 0000000000000000000000000000000000000000..3b9e42318f228157c7ee6cc2d1cfe25d7ca96f76 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/MainAbility2/MainAbility2.ts @@ -0,0 +1,100 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' +import commonEvent from '@ohos.commonEvent' +import dialogRequest from '@ohos.app.ability.dialogRequest' + +async function publishEvent() { + var event = 'ACTS_REQUEST_DIALOG_EVENT1'; + + var commonEventPublishData = { + parameters: { + instanceCount: 1, + } + }; + + commonEvent.publish(event, commonEventPublishData, () => { + console.log('============>publish event success.==========>>') + }); + +} + +export default class MainAbility2 extends Ability { + + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("MainAbility2 onCreate"); + globalThis.abilityWant2 = want; + globalThis.requestDialogSuccess = true; + + try { + let requestInfo = dialogRequest.getRequestInfo(want); + if (requestInfo) { + globalThis.validRequestInfo = true; + console.log("MainAbility2 requestInfo is valid"); + } else { + console.log("MainAbility2 requestInfo is invalid"); + } + + let requestCallback = dialogRequest.getRequestCallback(want); + if (requestCallback) { + console.log("MainAbility2 requestCallback is valid"); + globalThis.validRequestCallback = true; + let resultCode = { + result : dialogRequest.ResultCode.RESULT_CANCEL, + }; + let resultCode2 ={ + result : dialogRequest.ResultCode.RESULT_OK, + }; + console.log(`resultCjode2 is ${JSON.stringify(resultCode2)}`); + requestCallback.setRequestResult(resultCode); + } else { + console.log("MainAbility2 requestCallback is invalid"); + } + publishEvent(); + } catch { + console.log("MainAbility2 testRequest fail"); + } + + console.log("AbilityMultiInstanceAppA abilityWant = " + JSON.stringify( globalThis.abilityWant2)); + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("MainAbility2 onDestroy"); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("MainAbility2 onWindowStageCreate") + globalThis.abilityContext2 = this.context; + windowStage.setUIContent(this.context, "MainAbility/pages/second/second", null); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("MainAbility onWindowStageDestroy"); + } + + onForeground() { + // Ability has brought to foreground + console.log("MainAbility onForeground"); + } + + onBackground() { + // Ability has back to background + console.log("MainAbility onBackground"); + } +}; diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..0139025da06b1f125a12c77aa989106251687fad --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate'); + } + + onDestroy() { + console.log('TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate'); + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy'); + } + + onForeground() { + console.log('TestAbility onForeground'); + } + + onBackground() { + console.log('TestAbility onBackground'); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/pages/index.ets b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..f6f779205c21e2ab53194a70f3702d33870e8de5 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined; +var abilityDelegatorArguments = undefined; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]); + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare "); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + var cmd = 'aa start -d 0 -a com.acts.example.requestdialog.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters); + var debug = abilityDelegatorArguments.parameters["-D"]; + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end'); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0a3b0e1c4ec24c2300a7faabc9f9540be42fe8a --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/Ability.test.ets @@ -0,0 +1,95 @@ +/* + * 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 "@ohos/hypium" +import commonEvent from '@ohos.commonEvent' + +var subscriberInfo = { + events: ["ACTS_REQUEST_DIALOG_EVENT1", "ACTS_REQUEST_DIALOG_EVENT2"] +}; + +const CASE_TIMEOUT = 3000; +console.info("====>in Ability.test====>"); + +export default function abilityTest() { + describe('ActsRequestDialogTest', function () { + console.info("====>in ActsRequestDialogTest====>"); + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + /* + * @tc.number: ACTS_requestDialog_0100 + * @tc.name: Start Recent Ability with no permission. + * @tc.desc: reguest dialog service + */ + it('ACTS_requestDialog_0100', 0, async function (done) { + console.log('ACTS_requestDialog_0100====ACTS_requestDialog_0100 Subscribe CallBack data:====>" + JSON.stringify(data)); + + async function processInfoCheck(data) { + console.info('====> ACTS_requestDialog_0100 processInfoCheck=====>'); + expect(globalThis.requestDialogSuccess).assertTrue(); + expect(globalThis.validRequestInfo).assertTrue(); + expect(globalThis.validRequestCallback).assertTrue(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + done(); + } + + if (data.event == "ACTS_REQUEST_DIALOG_EVENT1") { + console.info('====> ACTS_startRecent_0100 ACTS_StartAbility_CommonEvent1 success=====>'); + + await sleep(500); + processInfoCheck(data); + } + } + + commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + console.info("====>ACTS_requestDialog_0100 Create Subscriber====>"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + try { + await globalThis.abilityContext.requestDialogService( + { + bundleName: 'com.acts.example.requestdialog', + abilityName: 'com.acts.example.requestdialog.MainAbility2', + }).then((data) => { + console.info("====>ACTS_requestDialog_0100 request end + data:" + JSON.stringify(data)); + resultCode = data.result; + }) + } catch (paramError) { + console.info("====>ACTS_requestDialog_0100 requestDialogSerivce paramError====>"); + } + }) + + function unSubscribeCallback() { + console.info("====>UnSubscribe0100 CallBack====>"); + } + + function timeout() { + console.log('ACTS_requestDialog_0100 timeout.'); + done(); + } + + id = setTimeout(timeout, CASE_TIMEOUT); + console.log('Start ACTS_requestDialog_0100 timer id : ' + id); + }) + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6a5bd8d95cac42bcdc862e9976dfc58d4cef99b --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 abilityTest from './Ability.test.ets' + + +export default function testsuite() { + + abilityTest() + +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/module.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9024cf9a649ea146577accc7a7c9c0fe90d17643 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/module.json @@ -0,0 +1,48 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "com.acts.example.requestdialog.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + }, + { + "name": "com.acts.example.requestdialog.MainAbility2", + "srcEntrance": "./ets/MainAbility2/MainAbility2.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "launchType":"standard", + "orientation": "portrait" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2977b612ec4595b13eaaffe3e8fc578e83c42d48 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsContextTest" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "app_name", + "value": "Demo" + } + ] +} diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..02221db61d317863114ff0ca4dd2b33586abff12 --- /dev/null +++ b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "MainAbility/pages/index/index", + "MainAbility/pages/second/second" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/signature/openharmony_sx.p7b b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..0c39397c9a7062da0f1b279c2163c8b98ff0fefe Binary files /dev/null and b/ability/ability_runtime/actsrequestdialogtest/actsrequestdialog/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets index 0bbb4d3a584fa66684434f52cadd18a504b31d9b..3704455b9fe2cbd42dd52f4ddd0f13d4046dce13 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets @@ -12,16 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import { describe, afterEach, it, expect } from '@ohos/hypium' -import formProvider from '@ohos.application.formProvider'; import FormInfo from '@ohos.application.formInfo'; import formInfoNew from '@ohos.app.form.formInfo'; import formError from '@ohos.application.formError'; import formHost from '@ohos.application.formHost'; -import errorManager from '@ohos.app.ability.errorManager'; import abilityConstant from '@ohos.app.ability.AbilityConstant' -import appManager from '@ohos.application.appManager' import appManagerNew from '@ohos.app.ability.appManager' import commonEvent from '@ohos.commonEvent'; import ability from '@ohos.ability.ability'; @@ -29,12 +26,11 @@ import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry import common from '@ohos.app.ability.common'; import contextConstant from "@ohos.app.ability.contextConstant" -var EXTENSION_INFO_ERR = 16000001 -var INNER_ERROR = 16000050 -var CROSS_USER_DENY = 201 -var INVALID_PARAM = 401 -var trueInfo; -var array = new Array(); +let EXTENSION_INFO_ERR = 16000001; +let INNER_ERROR = 16000050; +let CROSS_USER_DENY = 201; +let array = new Array(); +let TAG = ''; function sleep(time) { return new Promise((resolve)=>setTimeout(resolve,time)); } @@ -661,5 +657,115 @@ export default function ApiCoverTest() { done() }) }) + + /* + * @tc.number SUB_AA_AbilityAppManager_0100 + * @tc.name The form of a promise getRunningProcessInformation + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_AbilityAppManager_0100', 0, async function (done) { + TAG = 'SUB_AA_AbilityAppManager_0100'; + await appManagerNew.getRunningProcessInformation().then((data)=>{ + console.log(`${TAG} getRunningProcessInformation data ${JSON.stringify(data.length)}`); + for (let i = 0; i < data.length; i++) { + console.log(`${TAG} getRunningProcessInformation${i} : JSON.stringify(data[i])`); + expect(typeof (data[i].pid)).assertEqual("number"); + expect(data[i].pid).assertLarger(0); + expect(typeof (data[i].uid)).assertEqual("number"); + expect(data[i].uid).assertLarger(0); + expect(typeof (data[i].processName)).assertEqual("string"); + expect(data[i].processName.length).assertLarger(0); + expect(Array.isArray(data[i].bundleNames)).assertEqual(true); + expect(data[i].bundleNames.length).assertLarger(0); + } + done(); + }).catch((err)=>{ + console.log(`${TAG} getRunningProcessInformation err ${JSON.stringify(err)}`); + expect().assertFail(); + done(); + }) + }) + + /* + * @tc.number SUB_AA_AbilityAppManager_0200 + * @tc.name The form of a callback getRunningProcessInformation + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_AbilityAppManager_0200', 0, async function (done) { + TAG = 'SUB_AA_AbilityAppManager_0100'; + appManagerNew.getRunningProcessInformation((err, data) => { + console.log(`${TAG} getRunningProcessInformation data ${JSON.stringify(data.length)} + err: ${JSON.stringify(err)}`); + for (let i = 0; i < data.length; i++) { + console.log(`${TAG} getRunningProcessInformation${i} : JSON.stringify(data[i])`); + expect(typeof (data[i].pid)).assertEqual("number"); + expect(data[i].pid).assertLarger(0); + expect(typeof (data[i].uid)).assertEqual("number"); + expect(data[i].uid).assertLarger(0); + expect(typeof (data[i].processName)).assertEqual("string"); + expect(data[i].processName.length).assertLarger(0); + expect(Array.isArray(data[i].bundleNames)).assertEqual(true); + expect(data[i].bundleNames.length).assertLarger(0); + } + done(); + }) + }) + + /* + * @tc.number SUB_AA_ApplicationContext_0100 + * @tc.name The form of a promise getRunningProcessInformation + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_ApplicationContext_0100', 0, async function (done) { + TAG = 'SUB_AA_ApplicationContext_0100'; + await globalThis.applicationContext.getRunningProcessInformation().then((data)=>{ + console.log(`${TAG} getRunningProcessInformation data ${JSON.stringify(data.length)}`); + for (let i = 0; i < data.length; i++) { + console.log(`${TAG} getRunningProcessInformation${i} : JSON.stringify(data[i])`); + expect(typeof (data[i].pid)).assertEqual("number"); + expect(data[i].pid).assertLarger(0); + expect(typeof (data[i].uid)).assertEqual("number"); + expect(data[i].uid).assertLarger(0); + expect(typeof (data[i].processName)).assertEqual("string"); + expect(data[i].processName.length).assertLarger(0); + expect(Array.isArray(data[i].bundleNames)).assertEqual(true); + expect(data[i].bundleNames.length).assertLarger(0); + } + done(); + }).catch((err)=>{ + console.log(`${TAG} getRunningProcessInformation err ${JSON.stringify(err)}`); + expect().assertFail(); + done(); + }) + }) + + /* + * @tc.number SUB_AA_ApplicationContext_0200 + * @tc.name The form of a callback getRunningProcessInformation + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_ApplicationContext_0200', 0, async function (done) { + TAG = 'SUB_AA_ApplicationContext_0200'; + globalThis.applicationContext.getRunningProcessInformation((err, data) => { + console.log(`${TAG} getRunningProcessInformation data ${JSON.stringify(data.length)} + err: ${JSON.stringify(err)}`); + for (let i = 0; i < data.length; i++) { + console.log(`${TAG} getRunningProcessInformation${i} : JSON.stringify(data[i])`); + expect(typeof (data[i].pid)).assertEqual("number"); + expect(data[i].pid).assertLarger(0); + expect(typeof (data[i].uid)).assertEqual("number"); + expect(data[i].uid).assertLarger(0); + expect(typeof (data[i].processName)).assertEqual("string"); + expect(data[i].processName.length).assertLarger(0); + expect(Array.isArray(data[i].bundleNames)).assertEqual(true); + expect(data[i].bundleNames.length).assertLarger(0); + } + done(); + }) + }) }) } diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/WantAgentCover.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/WantAgentCover.test.ets index 7d9270e77250f6e879cfc73e0bc4fbc0ba5cedbb..82f674b08cf685d303a500ec8daf0a9c25e4071b 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/WantAgentCover.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/WantAgentCover.test.ets @@ -14,6 +14,7 @@ */ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import wantAgent from '@ohos.app.ability.wantAgent'; +import wantConstant from '@ohos.app.ability.wantConstant' var TAG export default function wantAgentCoverTest() { @@ -60,6 +61,8 @@ export default function wantAgentCoverTest() { }); setTimeout(() => { + expect(wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK) + .assertEqual('ability.params.backToOtherMissionStack'); expect(status).assertTrue(); expect(code1).assertEqual(2); done()