diff --git a/ability/ability_runtime/abilitymontior/entry/src/main/module.json b/ability/ability_runtime/abilitymontior/entry/src/main/module.json index ac51b9a2a9dcb09896c06ade25a5fbb897887893..479dd4d8d504633d9afcd5f941f6aa162d39f1fd 100644 --- a/ability/ability_runtime/abilitymontior/entry/src/main/module.json +++ b/ability/ability_runtime/abilitymontior/entry/src/main/module.json @@ -60,7 +60,7 @@ "launchType": "singleton" } ], - "reqPermissions": [ + "requestPermissions": [ { "name":"ohos.permission.START_ABILITIES_FROM_BACKGROUND", "reason":"need use ohos.permission.START_ABILITIES_FROM_BACKGROUND" diff --git a/ability/ability_runtime/context/BUILD.gn b/ability/ability_runtime/context/BUILD.gn index 6c4935d9fc2bfcbbd1def7eefce08624a0fa63d9..ff00821610fb3b999d160ab821975c8f4cbfcf35 100644 --- a/ability/ability_runtime/context/BUILD.gn +++ b/ability/ability_runtime/context/BUILD.gn @@ -21,6 +21,7 @@ group("context") { "actscreatemodulecontextassist:ActsCreateModuleContextAssist", "actscreatemodulecontextassistone:ActsCreateModuleContextAssistOne", "actscreatemodulecontexttest:ActsCreateModuleContextTest", + "actsstagecontext:actsstagecontext", "scene/defpermission:DefPermission", ] } diff --git a/ability/ability_runtime/context/actsstagecontext/BUILD.gn b/ability/ability_runtime/context/actsstagecontext/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..47abc75e204b802b6e328ab426344dab339d8c80 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/BUILD.gn @@ -0,0 +1,25 @@ +# 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") + +group("actsstagecontext") { + testonly = true + if (is_standard_system) { + deps = [ + "actsstagecontextassistone:ActsStageContextAssistOne", + "actsstagecontextassisttwo:ActsStageContextAssistTwo", + "actsstagecontextpropertiestest:ActsStageContextPropertiesTest", + ] + } +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/app.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..3eedf8c9dfc3d266698afb8045d7f0eb8c1f96e4 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.stagecontextpropertiestest", + "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 + } + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0341464a8de631a34787cb15a9d9266b29847a73 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsStageContextAssistOne" + } + ] +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/BUILD.gn b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..033c5a02cadcf60c68dadeaa9b407b2de8bf4e34 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/BUILD.gn @@ -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("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("ActsStageContextAssistOne") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":stagecontextassistone_js_assets", + ":stagecontextassistone_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsStageContextAssistOne" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("stagecontextassistone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("stagecontextassistone_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("stagecontextassistone_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":stagecontextassistone_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/Application/MyAbilityStage.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..84e69952d76b6d244a28188b9734268f106f63d5 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,23 @@ +/* +* 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.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.info("ActsStageContextAssistOne StageAbility onCreate") + globalThis.abilityStageContextA = this.context; + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a5c2a0434f36ea7732e34c5abfb6f37793e3a4b2 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/MainAbility/MainAbility.ts @@ -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 Ability from '@ohos.application.Ability' +import commonEvent from '@ohos.commonEvent' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.info('ActsStageContextAssistOne MainAbility3 onCreate') + } + + onDestroy() { + console.info('ActsStageContextAssistOne MainAbility3 onDestroy') + } + + onWindowStageCreate(windowStage) { + console.info('ActsStageContextAssistOne MainAbility3 onWindowStageCreate') + windowStage.setUIContent(this.context, 'pages/index', null) + } + + onWindowStageDestroy() { + console.info('ActsStageContextAssistOne MainAbility3 onWindowStageDestroy') + } + + onForeground() { + console.info('ActsStageContextAssistOne MainAbility3 onForeground') + globalThis.abilityContextA = this.context + commonEvent.publish("StartMainAbility3_CommonEvent_ContextOne", () => { + console.log("Publish StartMainAbility3_CommonEvent_ContextOne callback") + }) + } + + onBackground() { + console.info('ActsStageContextAssistOne MainAbility3 onBackground') + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/pages/index.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..46cbf8478ea057c90ac54be87cc5db177cbe3277 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/ets/pages/index.ets @@ -0,0 +1,49 @@ +/* +* 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. +*/ + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('MainAbility index aboutToAppear') + console.info('start run testcase!!!') + } + + @State message: string = 'MainAbility3 Hello' + 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/context/actsstagecontext/actsstagecontextassistone/entry/src/main/module.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..a6dae9dd13012243198601202fa5f1d05d0e7628 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/module.json @@ -0,0 +1,38 @@ +{ + "module": { + "name": "feature_assistone", + "type": "feature", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "MainAbility3", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility3", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "launchType": "specified", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..605115b2e7fe98cb36a1a5ec19594e215131a908 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "feature_MainAbility" + }, + { + "name": "app_name", + "value": "ActsStageContextAssistOne" + }, + { + "name": "description_application", + "value": "demo for test" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e291133c8b3c329611da5af30c299ec10589c7c2 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/signature/openharmony_sx.p7b b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassistone/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/app.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..17b1d50f0183c0063e3248ea223b97a35d790b67 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.actsstagecontextassisttwo", + "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/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ec48a8748ea2b8c0babde132baba30c5503a0918 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AbilityStageMonitor" + } + ] +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/BUILD.gn b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..18bf2348409426a8bfac354e8a4690c8384a7f61 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/BUILD.gn @@ -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("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("ActsStageContextAssistTwo") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":stagecontextassisttwo_js_assets", + ":stagecontextassisttwo_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsStageContextAssistTwo" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("stagecontextassisttwo_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("stagecontextassisttwo_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("stagecontextassisttwo_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":stagecontextassisttwo_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/Application/MyAbilityStage.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..d5309541bd41ca7b2c20266106f30bf21be2e342 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,93 @@ +/* +* 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.application.AbilityStage" +import commonEvent from '@ohos.commonEvent' + +function sleep(delay) { + let start = new Date().getTime(); + while (true) { + if (new Date().getTime() - start > delay) { + break; + } + } +} + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.info("ActsStageContextAssistTwo AbilityStage onCreate") + globalThis.abilityStageContextB = this.context + } + + onAcceptWant(want) { + console.log("ActsStageContextAssistTwo onAcceptWant called want:" + JSON.stringify(want)); + async function publishContext() { + let stageContextJson = { + 'cacheDir': globalThis.abilityStageContextB.cacheDir, 'tempDir': globalThis.abilityStageContextB.tempDir, + 'filesDir': globalThis.abilityStageContextB.filesDir, 'distributedFilesDir': globalThis.abilityStageContextB.distributedFilesDir, + 'databaseDir': globalThis.abilityStageContextB.databaseDir, 'preferencesDir': globalThis.abilityStageContextB.preferencesDir, + 'bundleCodeDir': globalThis.abilityStageContextB.bundleCodeDir + }; + + let stageAppContext = globalThis.abilityStageContextB.getApplicationContext() + + let stageAppContextJson = { + 'cacheDir': stageAppContext.cacheDir, 'tempDir': stageAppContext.tempDir, 'filesDir': stageAppContext.filesDir, + 'distributedFilesDir': stageAppContext.distributedFilesDir, 'databaseDir': stageAppContext.databaseDir, + 'preferencesDir': stageAppContext.preferencesDir, 'bundleCodeDir': stageAppContext.bundleCodeDir + }; + + let bundleContext = globalThis.abilityStageContextB.createBundleContext("com.example.actsstagecontextassisttwo"); + + let result = await bundleContext.resourceManager.getString(16777219) + + let appBundleContext = stageAppContext.createBundleContext("com.example.actsstagecontextassisttwo"); + + let result1 = await appBundleContext.resourceManager.getString(16777219) + + console.log("ActsStageContextAssistTwo getLabel " + JSON.stringify(result1)) + + let stageBundleContextJson = { + 'cacheDir': bundleContext.cacheDir, 'tempDir': bundleContext.tempDir, 'filesDir': bundleContext.filesDir, + 'distributedFilesDir': bundleContext.distributedFilesDir, 'databaseDir': bundleContext.databaseDir, + 'preferencesDir': bundleContext.preferencesDir, 'bundleCodeDir': bundleContext.bundleCodeDir + }; + + let stageAppBundleContextJson = { + 'cacheDir': appBundleContext.cacheDir, 'tempDir': appBundleContext.tempDir, 'filesDir': appBundleContext.filesDir, + 'distributedFilesDir': appBundleContext.distributedFilesDir, 'databaseDir': appBundleContext.databaseDir, + 'preferencesDir': appBundleContext.preferencesDir, 'bundleCodeDir': appBundleContext.bundleCodeDir + }; + + let commonEventData = { + parameters: { + abilityStageContextAssistOne: stageContextJson, + abilityStageAppContextAssistOne: stageAppContextJson, + abilityStageLabel: result, + abilityStageAppLabel: result1, + abilityStageBundleContxtAssistOne: stageBundleContextJson, + abilityStageAppBundleContextAssistOne: stageAppBundleContextJson + } + } + commonEvent.publish("AssistContextTwo_StageAbilityA_Start_CommonEvent", commonEventData, () => { + console.log("Publish AssistContextTwo_StageAbilityA_Start_CommonEvent callback") + }) + } + publishContext() + sleep(500) + let abilityId = want.parameters.startId.toString(); + return abilityId; + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..dd286cedb98745eb8e47d4033122c75ed00f02e1 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,100 @@ +/* +* 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.application.Ability' +import commonEvent from '@ohos.commonEvent' +import bundle from '@ohos.bundle'; +import dataAbility from '@ohos.data.dataAbility'; + +export default class MainAbility extends Ability { + onCreate(want: any, launchParam: any) { + console.info('ActsStageContextAssistTwo MainAbility4 onCreate') + } + + onDestroy() { + console.info('MainAbilityMonitor onDestroy') + } + + onWindowStageCreate(windowStage) { + console.info('ActsStageContextAssistTwo MainAbility4 onWindowStageCreate') + windowStage.setUIContent(this.context, 'MainAbility/pages/index', null) + } + + onWindowStageDestroy() { + console.info('ActsStageContextAssistTwo MainAbility4 onWindowStageDestroy') + } + + async onForeground() { + console.info('ActsStageContextAssistTwo MainAbility4 onForeground') + let contextJson = { + 'cacheDir': this.context.cacheDir, 'tempDir': this.context.tempDir, 'filesDir': this.context.filesDir, + 'distributedFilesDir': this.context.distributedFilesDir, 'databaseDir': this.context.databaseDir, + 'preferencesDir': this.context.preferencesDir, 'bundleCodeDir': this.context.bundleCodeDir + }; + + let abilityAppContext = this.context.getApplicationContext() + + let appContextJson = { + 'cacheDir': abilityAppContext.cacheDir, 'tempDir': abilityAppContext.tempDir, 'filesDir': abilityAppContext.filesDir, + 'distributedFilesDir': abilityAppContext.distributedFilesDir, 'databaseDir': abilityAppContext.databaseDir, + 'preferencesDir': abilityAppContext.preferencesDir, 'bundleCodeDir': abilityAppContext.bundleCodeDir + }; + + let bundleContext = this.context.createBundleContext("com.example.actsstagecontextassisttwo") + + let bundleAppContext = abilityAppContext.createBundleContext("com.example.actsstagecontextassisttwo") + + let result = await bundleContext.resourceManager.getString(16777219) + + let bundleContextJson = { + 'cacheDir': bundleContext.cacheDir, 'tempDir': bundleContext.tempDir, 'filesDir': bundleContext.filesDir, + 'distributedFilesDir': bundleContext.distributedFilesDir, 'databaseDir': bundleContext.databaseDir, + 'preferencesDir': bundleContext.preferencesDir, 'bundleCodeDir': bundleContext.bundleCodeDir + }; + + let appBundleContextJson = { + 'cacheDir': bundleAppContext.cacheDir, 'tempDir': bundleAppContext.tempDir, 'filesDir': bundleAppContext.filesDir, + 'distributedFilesDir': bundleAppContext.distributedFilesDir, 'databaseDir': bundleAppContext.databaseDir, + 'preferencesDir': bundleAppContext.preferencesDir, 'bundleCodeDir': bundleAppContext.bundleCodeDir + }; + + let errCode; + + try { + this.context.createBundleContext("com.example.stagecontextpropertiestest") + } catch (error) { + console.log("ActsStageContextAssistTwo createBundleContext is error:" + JSON.stringify(error)) + errCode = error.code + } + + let commonEventData = { + parameters: { + abilityContextAssistTwo: contextJson, + abilityAppContextAssistTwo: appContextJson, + abilityLabel: result, + abilityBundleContextAssistTwo: bundleContextJson, + abilityAppBundleContextAssistTwo: appBundleContextJson, + abilityBundleContextTest: errCode + } + } + commonEvent.publish("StartMainAbility4_CommonEvent_ContextOne", commonEventData, () => { + console.log("Publish StartMainAbility4_CommonEvent_ContextOne callback") + }) + } + + onBackground() { + console.info('ActsStageContextAssistTwo MainAbility4 onBackground') + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/pages/index.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1c0f2c9122aa6dcf2ae920ad25df61d783654ea --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,49 @@ +/* +* 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. +*/ + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('MainAbility index aboutToAppear') + console.info('start run testcase!!!') + } + + @State message: string = 'MainAbility4 Hello' + 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/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/module.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..6bacd2189ba6826efab70ce28cadae7f35cdb9d6 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/module.json @@ -0,0 +1,38 @@ +{ + "module": { + "name": "entry_assisttow", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "MainAbility4", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility4", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "launchType": "specified", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6cdc973204d451ad03b7dd133c05652792e74544 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "entry_MainAbility" + }, + { + "name": "app_name", + "value": "ActsStageContextAssistTwo" + }, + { + "name": "description_application", + "value": "demo for test" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..951f0a2b8d54f94311cb88cbedae68c9d56fcb49 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/signature/openharmony_sx.p7b b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextassisttwo/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/app.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..bc1d390ecd3d1d461a69e35aa5c3a550a615fd18 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.example.stagecontextpropertiestest", + "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/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ec48a8748ea2b8c0babde132baba30c5503a0918 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AbilityStageMonitor" + } + ] +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/BUILD.gn b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e14dbde7bfe7d6681cdd0899b65d8868675d8b4c --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/BUILD.gn @@ -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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsStageContextPropertiesTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":stagecontextproperties_js_assets", + ":stagecontextproperties_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsStageContextPropertiesTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("stagecontextproperties_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("stagecontextproperties_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("stagecontextproperties_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":stagecontextproperties_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/Test.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..9595408064924e7b01b338ad084a4b7b49a9d65f --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/Test.json @@ -0,0 +1,23 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.example.stagecontextpropertiestest", + "module-name": "entry_test", + "shell-timeout": "600000", + "testcase-timeout": "15000" + }, + "kits": [ + { + "test-file-name": [ + "ActsStageContextPropertiesTest.hap", + "ActsStageContextAssistOne.hap", + "ActsStageContextAssistTwo.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} + diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/Application/MyAbilityStage.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..a5252dd1cf64c19339b511abf33634c978ca545b --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,23 @@ +/* +* 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.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.info("MyAbilityStageMonitor onCreate") + globalThis.abilityStageContext = this.context + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..1e2e87f4f85afad51bb5b9825fe09e73a58758b1 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,61 @@ +/* + * 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.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("ActsStageContextPropertiesTest MainAbility onCreate") + globalThis.abilityWant = want; + globalThis.abilityContext = this.context + let abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("ActsStageContextPropertiesTest MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("ActsStageContextPropertiesTest MainAbility onWindowStageCreate") + + windowStage.setUIContent(this.context, "pages/index/index", null) + console.log("ActsStageContextPropertiesTest MainAbility onWindowStageCreate finish") + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("ActsStageContextPropertiesTest MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("ActsStageContextPropertiesTest MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("ActsStageContextPropertiesTest MainAbility onBackground") + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility2/MainAbility2.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility2/MainAbility2.ts new file mode 100644 index 0000000000000000000000000000000000000000..51d5acc1b1bbde2060690997374162f178c0cc39 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/MainAbility2/MainAbility2.ts @@ -0,0 +1,53 @@ +/* + * 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.application.Ability' +import commonEvent from '@ohos.commonEvent' + +export default class MainAbility2 extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("ActsStageContextPropertiesTest MainAbility2 onCreate") + globalThis.abilityWant = want; + globalThis.abilityContext2 = this.context + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("ActsStageContextPropertiesTest MainAbility2 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("ActsStageContextPropertiesTest MainAbility2 onWindowStageCreate") + + windowStage.setUIContent(this.context, "pages/secone/second ", null) + console.log("ActsStageContextPropertiesTest MainAbility2 onWindowStageCreate finish") + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("ActsStageContextPropertiesTest MainAbility2 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("ActsStageContextPropertiesTest MainAbility2 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("ActsStageContextPropertiesTest MainAbility2 onBackground") + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..97d54bf53d891f7bac91020da534621ccdaec03b --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,75 @@ +/* +* 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' + +let abilityDelegator = undefined +let 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() + globalThis.abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + let cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + 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/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0a14fd4ec919058e6e7913e40e35c574ddb18f1 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/pages/index/index.ets @@ -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. + */ + + +@Entry +@Component +struct Index { + aboutToAppear(){ + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('MainAbility 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/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/pages/second/second.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..23c5e3b3ad9029d36043199535a4c63560154d53 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/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 = "SecondMainAbility 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/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..19eec40cd02f2140c00aba8b7786e2cd4b68272d --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2022 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import stageContextPropertiesTest from './StageContextProperties.test' + +export default function testsuite() { + stageContextPropertiesTest(globalThis.abilityContext) +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/StageContextProperties.test.ets b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/StageContextProperties.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..21c002b9c9ac50aa449f7c9e4a1a50a18d907f87 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/ets/test/StageContextProperties.test.ets @@ -0,0 +1,1141 @@ +/* + * 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 { describe, it, expect, afterEach, beforeAll } from '@ohos/hypium' +import commonEvent from '@ohos.commonEvent' + +let Subscriber; +let TAG; + +let subscriberInfo_AbilityContext = { + events: ["StartMainAbility3_CommonEvent_ContextOne", "StartMainAbility4_CommonEvent_ContextOne", + "AssistContextTwo_StageAbilityA_Start_CommonEvent"], +}; + +export default function stageContextPropertiesTest(abilityContext) { + describe('ActsStageContextPropertiesTest', function () { + + beforeAll(async (done) => { + console.log("ActsStageContextPropertiesTest afterAll called"); + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility2" + }).then((data) => { + console.log('ActsStageContextPropertiesTest - startMainAbility2: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("ActsStageContextPropertiesTest - startMainAbility2 failed: " + + JSON.stringify(err)); + done() + }) + + setTimeout(function () { + console.log("ActsStageContextPropertiesTest afterAll end"); + done(); + }, 3000); + }) + + afterEach(async (done) => { + console.log("ActsStageContextPropertiesTest afterEach called"); + let wantInfo = { + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility" + } + await abilityContext.startAbility(wantInfo).then((data) => { + console.log("ActsStageContextPropertiesTest startMainAbility data : " + JSON.stringify(data)); + }).catch((err) => { + console.log("ActsStageContextPropertiesTest startMainAbility err : " + JSON.stringify(err)); + }) + + setTimeout(function () { + console.log("ActsStageContextPropertiesTest afterEach end"); + done(); + }, 1500); + }) + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0100 + * @tc.name: Check that context paths of different Ability in the same hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0100', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0100" + console.log(TAG + "--- start"); + + checkAbilityContextDir(); + checkContextDirEqualA(abilityContext, globalThis.abilityContext2); + done() + console.log(TAG + "--- end"); + + + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0200 + * @tc.name: Check that context paths of different Ability in the same hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0200', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0200" + console.log(TAG + "--- start"); + checkApplicationContextDir(abilityContext.getApplicationContext()); + checkApplicationContextDir(globalThis.abilityStageContext.getApplicationContext()); + checkApplicationContextDir(globalThis.abilityContext2.getApplicationContext()); + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityContext2.getApplicationContext()) + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityStageContext.getApplicationContext()) + done() + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0300 + * @tc.name: Check that context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0300', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0300" + console.log(TAG + " --- start"); + + checkAbilityContextDir(); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + checkContextDirEqualB(abilityContext, globalThis.abilityContextA) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0400 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0400', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0400" + console.log(TAG + " --- start"); + + checkAbilityStageContextDir(); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + checkContextDirEqualB(globalThis.abilityStageContext, globalThis.abilityStageContextA) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0500 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0500', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0500" + console.log(TAG + " --- start"); + checkApplicationContextDir(abilityContext.getApplicationContext()); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityContextA.getApplicationContext()) + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityStageContextA.getApplicationContext()) + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityStageContext.getApplicationContext()) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0600 + * @tc.name: Check that context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0600', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0600" + console.log(TAG + " --- start"); + checkAbilityContextDir(); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == "StartMainAbility4_CommonEvent_ContextOne") { + checkContextDirEqualC(abilityContext, data.parameters.abilityContextAssistTwo) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 1, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0700 + * @tc.name: Check that context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0700', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0700" + console.log(TAG + " --- start"); + checkAbilityStageContextDir(); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == "AssistContextTwo_StageAbilityA_Start_CommonEvent") { + checkContextDirEqualC(abilityContext, data.parameters.abilityStageContextAssistOne) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 2, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0800 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_0800', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0800" + console.log(TAG + " --- start"); + let num = 0; + let abilityAppContext; + let abilityStageAppContext; + checkApplicationContextDir(abilityContext.getApplicationContext()); + + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + console.log(TAG + " AssistContextTwo_StageAbilityA_Start_CommonEvent") + num++; + abilityStageAppContext = data.parameters.abilityStageAppContextAssistOne + } + if (data.event == 'StartMainAbility4_CommonEvent_ContextOne') { + console.log(TAG + " StartMainAbility4_CommonEvent_ContextOne") + num++; + abilityAppContext = data.parameters.abilityAppContextAssistTwo + } + if (num == 2) { + console.log(TAG + " start expect"); + checkContextDirEqualA(abilityContext.getApplicationContext(), abilityAppContext) + checkContextDirEqualA(abilityContext.getApplicationContext(), abilityStageAppContext) + checkContextDirEqualA(abilityContext.getApplicationContext(), + globalThis.abilityStageContext.getApplicationContext()) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 3, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_0900 + * @tc.name: Check that label paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 0 + */ + it('SUB_AA_OpenHarmony_Context_0900', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_0900" + console.log(TAG + " --- start"); + let result = await abilityContext.resourceManager.getString(16777219); + console.log(TAG + " : result = " + JSON.stringify(result)); + expect(result).assertEqual("feature_MainAbility"); + done(); + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1000 + * @tc.name: Check that label paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1000', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1000" + console.log(TAG + " --- start"); + let result = await globalThis.abilityStageContext.resourceManager.getString(16777219); + console.log(TAG + " : result = " + JSON.stringify(result)); + expect(result).assertEqual("feature_MainAbility"); + done(); + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1100 + * @tc.name: Check that label paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1100', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1100" + console.log(TAG + " --- start"); + let result = await globalThis.abilityStageContext.getApplicationContext() + .resourceManager.getString(16777219); + console.log(TAG + " : result = " + JSON.stringify(result)); + expect(result).assertEqual("feature_MainAbility"); + done(); + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1200 + * @tc.name: Check that label paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1200', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1200" + console.log(TAG + " --- start"); + + async function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + let result = await globalThis.abilityContextA.resourceManager.getString(16777219); + console.log(TAG + " : result = " + JSON.stringify(result)); + expect(result).assertEqual("feature_MainAbility"); + checkContextDirEqualB(abilityContext, globalThis.abilityContextA) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1300 + * @tc.name: Call createBundleContext through context and pass in the wrong package + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1300', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1300" + console.log(TAG + " --- start"); + try { + abilityContext.createBundleContext(" "); + expect.assertFail() + } catch (error) { + console.log(TAG + " createBundleContext = " + JSON.stringify(error)); + done() + } + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1400 + * @tc.name: The resource obtained through getString is the same as config.json in the label resources are the same + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1400', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1400" + console.log(TAG + " --- start"); + let bundleContext = abilityContext.createBundleContext("com.example.stagecontextpropertiestest"); + let result = await bundleContext.resourceManager.getString(16777219); + console.log(TAG + " : result = " + JSON.stringify(result)); + expect(result).assertEqual("feature_MainAbility"); + done(); + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1500 + * @tc.name: The resource obtained through getString is the same as config.json in the label resources are the same + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1500', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1500" + console.log(TAG + " --- start"); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'StartMainAbility4_CommonEvent_ContextOne') { + expect(data.parameters.abilityLabel).assertEqual("entry_MainAbility"); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 4, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1600 + * @tc.name: The resource obtained through getString is the same as config.json in the label resources are the same + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1600', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1600" + console.log(TAG + " --- start"); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + expect(data.parameters.abilityStageLabel).assertEqual("entry_MainAbility"); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 5, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1700 + * @tc.name: The resource obtained through getString is the same as config.json in the label resources are the same + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1700', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1700" + console.log(TAG + " --- start"); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + expect(data.parameters.abilityStageAppLabel).assertEqual("entry_MainAbility"); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 6, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1800 + * @tc.name: Check that context paths of different Ability in the same hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1800', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1800" + console.log(TAG + " --- start"); + let abilityBundleContext1 = abilityContext.createBundleContext("com.example.stagecontextpropertiestest"); + let abilityBundleContext2 = globalThis.abilityContext2 + .createBundleContext("com.example.stagecontextpropertiestest"); + checkBundleContextDir(abilityBundleContext1); + checkContextDirEqualA(abilityBundleContext1, abilityBundleContext2); + console.log(TAG + " --- end"); + done() + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_1900 + * @tc.name: Check that ApplicationContext paths of different Ability in the same hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_1900', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_1800" + console.log(TAG + " --- start"); + let abilityBundleContext1 = abilityContext.createBundleContext("com.example.stagecontextpropertiestest"); + let abilityBundleContext2 = globalThis.abilityContext2 + .createBundleContext("com.example.stagecontextpropertiestest"); + let abilityStageBundleContext2 = globalThis.abilityStageContext + .createBundleContext("com.example.stagecontextpropertiestest"); + checkBundleContextDir(abilityBundleContext1); + checkContextDirEqualA(abilityBundleContext1, abilityBundleContext2); + checkContextDirEqualA(abilityBundleContext1, abilityStageBundleContext2); + console.log(TAG + " --- end"); + done() + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2000 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2000', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2000" + console.log(TAG + " --- start"); + let abilityBundleContext1 = abilityContext.createBundleContext("com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + let abilityBundleContext2 = globalThis.abilityContextA.createBundleContext( + "com.example.stagecontextpropertiestest"); + checkContextDirEqualA(abilityBundleContext1, abilityBundleContext2); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2100 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2100', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2100" + console.log(TAG + " --- start"); + let abilityStageBundleContext1 = globalThis.abilityStageContext.createBundleContext( + "com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityStageBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + let abilityBundleContext2 = globalThis.abilityStageContextA.createBundleContext( + "com.example.stagecontextpropertiestest"); + checkContextDirEqualA(abilityStageBundleContext1, abilityBundleContext2); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2200 + * @tc.name: Check that ApplicationContext paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2200', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2200" + console.log(TAG + " --- start"); + let abilityBundleContext1 = abilityContext.getApplicationContext() + .createBundleContext("com.example.stagecontextpropertiestest") + let abilityStageBundleContext1 = globalThis.abilityStageContext.getApplicationContext() + .createBundleContext( + "com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + let abilityBundleContext2 = abilityContext.getApplicationContext() + .createBundleContext("com.example.stagecontextpropertiestest") + let abilityStageBundleContext2 = globalThis.abilityStageContext.getApplicationContext() + .createBundleContext( + "com.example.stagecontextpropertiestest"); + checkContextDirEqualA(abilityBundleContext1, abilityStageBundleContext1); + checkContextDirEqualA(abilityBundleContext2, abilityStageBundleContext2); + checkContextDirEqualA(abilityBundleContext1, abilityStageBundleContext2); + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.stagecontextpropertiestest", + abilityName: "MainAbility3", + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2300 + * @tc.name: Check that Context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2300', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2300" + console.log(TAG + " --- start"); + let abilityBundleContext1 = abilityContext.createBundleContext("com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'StartMainAbility4_CommonEvent_ContextOne') { + checkAssistHapBundleContextDir(data.parameters.abilityBundleContextAssistTwo) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 7, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2400 + * @tc.name: Check that Context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2400', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2400" + console.log(TAG + " --- start"); + let abilityStageBundleContext1 = globalThis.abilityStageContext + .createBundleContext("com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityStageBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + checkAssistHapBundleContextDir(data.parameters.abilityStageBundleContxtAssistOne) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 8, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2500 + * @tc.name: Check that ApplicationContex paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2500', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2500" + console.log(TAG + " --- start"); + let num = 0; + let abilityStageAppBundleContext; + let abilityAppBundleContext; + let abilityAppBundleContext1 = globalThis.abilityStageContext.getApplicationContext() + .createBundleContext("com.example.stagecontextpropertiestest"); + let abilityStageAppBundleContext1 = globalThis.abilityStageContext.getApplicationContext() + .createBundleContext("com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityAppBundleContext1); + checkContextDirEqualA(abilityAppBundleContext1, abilityStageAppBundleContext1) + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + if (data.event == 'AssistContextTwo_StageAbilityA_Start_CommonEvent') { + console.log(TAG + " AssistContextTwo_StageAbilityA_Start_CommonEvent") + num++; + abilityStageAppBundleContext = data.parameters.abilityStageAppContextAssistOne + } + if (data.event == 'StartMainAbility4_CommonEvent_ContextOne') { + console.log(TAG + " StartMainAbility4_CommonEvent_ContextOne") + num++; + abilityAppBundleContext = data.parameters.abilityAppContextAssistTwo + } + if (num == 2) { + console.log(TAG + " start expect"); + checkAssistHapBundleContextDir(abilityAppBundleContext) + checkContextDirEqualA(abilityAppBundleContext, abilityStageAppBundleContext) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 9, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + /** + * @tc.number: SUB_AA_OpenHarmony_Context_2600 + * @tc.name: Check that Context paths of different Ability in the different hap are the same. + * @tc.desc: Function test + * @tc.level 3 + */ + it('SUB_AA_OpenHarmony_Context_2600', 0, async function (done) { + TAG = "SUB_AA_OpenHarmony_Context_2600" + console.log(TAG + " --- start"); + let abilityBundleContext1 = globalThis.abilityStageContext + .createBundleContext("com.example.stagecontextpropertiestest"); + + checkBundleContextDir(abilityBundleContext1); + + function SubscribeCallBack(err, data) { + console.log(TAG + " Subscribe CallBack data: " + JSON.stringify(data) + + "err: " + JSON.stringify(err)); + if (data.event == 'StartMainAbility4_CommonEvent_ContextOne') { + expect(data.parameters.abilityBundleContextTest).assertEqual(401) + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + } + } + + await commonEvent.createSubscriber(subscriberInfo_AbilityContext).then(async (data) => { + console.log(TAG + " Create Subscriber"); + Subscriber = data; + await commonEvent.subscribe(Subscriber, SubscribeCallBack); + }) + + function UnSubscribeCallback() { + console.log(TAG + " UnSubscribe CallBack"); + done(); + } + + await abilityContext.startAbility({ + bundleName: "com.example.actsstagecontextassisttwo", + abilityName: "MainAbility4", + parameters: { + startId: 10, + } + }).then((data) => { + console.log(TAG + ' - startAbility: ' + JSON.stringify(data)); + }).catch((err) => { + console.log(TAG + " - start failed" + JSON.stringify(err)); + expect.assertFail() + done() + }) + }); + + function checkApplicationContextDir(applicationContext) { + expect(applicationContext.cacheDir).assertEqual("/data/storage/el2/base/cache"); + expect(applicationContext.tempDir).assertEqual("/data/storage/el2/base/temp"); + expect(applicationContext.filesDir).assertEqual("/data/storage/el2/base/files"); + expect(applicationContext.distributedFilesDir).assertEqual("/data/storage/el2/distributedfiles"); + expect(applicationContext.databaseDir).assertEqual("/data/storage/el2/database"); + expect(applicationContext.preferencesDir).assertEqual("/data/storage/el2/base/preferences"); + expect(applicationContext.bundleCodeDir).assertEqual("/data/storage/el1/bundle"); + } + + function checkAbilityContextDir() { + expect(abilityContext.cacheDir).assertEqual("/data/storage/el2/base/haps/entry_test/cache"); + expect(abilityContext.tempDir).assertEqual("/data/storage/el2/base/haps/entry_test/temp"); + expect(abilityContext.filesDir).assertEqual("/data/storage/el2/base/haps/entry_test/files"); + expect(abilityContext.distributedFilesDir).assertEqual("/data/storage/el2/distributedfiles"); + expect(abilityContext.databaseDir).assertEqual("/data/storage/el2/database/entry_test"); + expect(abilityContext.preferencesDir).assertEqual("/data/storage/el2/base/haps/entry_test/preferences"); + expect(abilityContext.bundleCodeDir).assertEqual("/data/storage/el1/bundle"); + } + + function checkContextDirEqualA(abilityContext, abilityContext2) { + expect(abilityContext.cacheDir).assertEqual(abilityContext2.cacheDir); + expect(abilityContext.tempDir).assertEqual(abilityContext2.tempDir); + expect(abilityContext.filesDir).assertEqual(abilityContext2.filesDir); + expect(abilityContext.distributedFilesDir).assertEqual(abilityContext2.distributedFilesDir); + expect(abilityContext.databaseDir).assertEqual(abilityContext2.databaseDir); + expect(abilityContext.storageDir).assertEqual(abilityContext2.storageDir); + expect(abilityContext.bundleCodeDir).assertEqual(abilityContext2.bundleCodeDir); + } + + function checkContextDirEqualB(abilityContext, abilityContext2) { + expect(abilityContext2.cacheDir == "/data/storage/el2/base/haps/feature_assistone/cache" && + abilityContext2.cacheDir != abilityContext.cacheDir).assertTrue(); + expect(abilityContext2.databaseDir == "/data/storage/el2/database/feature_assistone" && + abilityContext2.databaseDir != abilityContext.databaseDir).assertTrue(); + expect(abilityContext2.filesDir == "/data/storage/el2/base/haps/feature_assistone/files" && + abilityContext2.filesDir != abilityContext.filesDir).assertTrue(); + expect(abilityContext2.preferencesDir == "/data/storage/el2/base/haps/feature_assistone/preferences" && + abilityContext2.preferencesDir != abilityContext.preferencesDir).assertTrue(); + expect(abilityContext2.tempDir == "/data/storage/el2/base/haps/feature_assistone/temp" && + abilityContext2.tempDir != abilityContext.tempDir).assertTrue(); + expect(abilityContext.distributedFilesDir).assertEqual(abilityContext2.distributedFilesDir); + expect(abilityContext.bundleCodeDir).assertEqual(abilityContext2.bundleCodeDir); + } + + function checkContextDirEqualC(abilityContext, abilityContext2) { + expect(abilityContext2.cacheDir == "/data/storage/el2/base/haps/entry_assisttow/cache" && + abilityContext2.cacheDir != abilityContext.cacheDir).assertTrue(); + expect(abilityContext2.databaseDir == "/data/storage/el2/database/entry_assisttow" && + abilityContext2.databaseDir != abilityContext.databaseDir).assertTrue(); + expect(abilityContext2.filesDir == "/data/storage/el2/base/haps/entry_assisttow/files" && + abilityContext2.filesDir != abilityContext.filesDir).assertTrue(); + expect(abilityContext2.preferencesDir == "/data/storage/el2/base/haps/entry_assisttow/preferences" && + abilityContext2.preferencesDir != abilityContext.preferencesDir).assertTrue(); + expect(abilityContext2.tempDir == "/data/storage/el2/base/haps/entry_assisttow/temp" && + abilityContext2.tempDir != abilityContext.tempDir).assertTrue(); + expect(abilityContext.distributedFilesDir).assertEqual(abilityContext2.distributedFilesDir); + expect(abilityContext.bundleCodeDir).assertEqual(abilityContext2.bundleCodeDir); + } + + function checkAbilityStageContextDir() { + expect(globalThis.abilityStageContext.cacheDir).assertEqual("/data/storage/el2/base/haps/entry_test/cache"); + expect(globalThis.abilityStageContext.tempDir).assertEqual("/data/storage/el2/base/haps/entry_test/temp"); + expect(globalThis.abilityStageContext.filesDir).assertEqual("/data/storage/el2/base/haps/entry_test/files"); + expect(globalThis.abilityStageContext.distributedFilesDir).assertEqual("/data/storage/el2/distributedfiles"); + expect(globalThis.abilityStageContext.databaseDir).assertEqual("/data/storage/el2/database/entry_test"); + expect(globalThis.abilityStageContext.preferencesDir).assertEqual("/data/storage/el2/base/haps/entry_test/preferences"); + expect(globalThis.abilityStageContext.bundleCodeDir).assertEqual("/data/storage/el1/bundle"); + } + + function checkBundleContextDir(bundleContext) { + expect(bundleContext.bundleCodeDir).assertEqual("/data/bundles/com.example.stagecontextpropertiestest"); + expect(bundleContext.tempDir).assertEqual("/data/app/el2/100/base/com.example.stagecontextpropertiestest/temp"); + expect(bundleContext.filesDir).assertEqual("/data/app/el2/100/base/com.example.stagecontextpropertiestest/files"); + expect(bundleContext.cacheDir).assertEqual("/data/app/el2/100/base/com.example.stagecontextpropertiestest/cache"); + expect(bundleContext.databaseDir).assertEqual("/data/app/el2/100/database/com.example.stagecontextpropertiestest"); + expect(bundleContext.preferencesDir).assertEqual("/data/app/el2/100/base/com.example.stagecontextpropertiestest/preferences"); + expect(bundleContext.distributedFilesDir).assertEqual("/mnt/hmdfs/100/device_view/local/data/com.example.stagecontextpropertiestest"); + } + + function checkAssistHapBundleContextDir(bundleContext) { + expect(bundleContext.bundleCodeDir).assertEqual("/data/bundles/com.example.actsstagecontextassisttwo"); + expect(bundleContext.tempDir).assertEqual("/data/app/el2/100/base/com.example.actsstagecontextassisttwo/temp"); + expect(bundleContext.filesDir).assertEqual("/data/app/el2/100/base/com.example.actsstagecontextassisttwo/files"); + expect(bundleContext.cacheDir).assertEqual("/data/app/el2/100/base/com.example.actsstagecontextassisttwo/cache"); + expect(bundleContext.databaseDir).assertEqual("/data/app/el2/100/database/com.example.actsstagecontextassisttwo"); + expect(bundleContext.preferencesDir).assertEqual("/data/app/el2/100/base/com.example.actsstagecontextassisttwo/preferences"); + expect(bundleContext.distributedFilesDir).assertEqual("/mnt/hmdfs/100/device_view/local/data/com.example.actsstagecontextassisttwo"); + } + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/module.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..18930cb5410f86e71e80171ec54afb5b1b2a88cd --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/module.json @@ -0,0 +1,61 @@ +{ + "module": { + "name": "entry_test", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "MainAbility2", + "srcEntrance": "./ets/MainAbility2/MainAbility2.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.START_ABILITIES_FROM_BACKGROUND", + "reason":"need use ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d42dffab203d65da7a728e0b1be520e46ae2a2ff --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "description" + }, + { + "name": "app_name", + "value": "ActsStageContextPropertiesTest" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "entry_MainAbility" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/signature/openharmony_sx.p7b b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/ability/ability_runtime/context/actsstagecontext/actsstagecontextpropertiestest/signature/openharmony_sx.p7b differ